Chef and Waiter Classes
Code the Chef and Waiter classes described in the previous section
Shape Class Hierarchy (Tree)
Given this class hierarchy (tree):
Shape Rectangle Square RightTriangle
📋
Here is our problem write-up:
Shape is abstract.
Shape has an ivar named "description" of type "String"
We want to construct all Shapes with "newDescription" as the one constructor method parameter
Rectangle has two ivars: width and height (ints)
Square has no ivars
RightTriangle has two ivars: base and height (ints)
We want to construct Rectangle's with parameters: newDescription, newWidth, newHeight
We want to construct Square's with parameters: newDescription, newSide (note that newSide is the side dimension)
We want to construct RightTriangle's with parameters: newDescription, newWidth, newHeight
Shape has an
abstract
method "computeArea" that returns the (int) area of the shape (no method parameters)
Shape has an
abstract
method "computePerimeter" that returns the (int) area of the shape (no method parameters)
Implement Shape, Rectangle, Square, RightTriangle
Introduction To Objects With Java (Chapter 502 - Inheritance)
Chapter 502 - Inheritance
Challenge
Contents
Concepts
Is-a
Java
Methods
Constructors
Abstract
Challenge
Chapter
Top
Search
TOC