| Homework 5 should be
turned in as a printout of your program before class/lab begins on
Thursday.
Your program is still expected to run in DrScheme: ProfessorJ
Intermediate. Printout should contain your first and last name, as well as the text Hw 5 |
| abstract class
Furniture { //To report the price of this Furniture abstract double price(); } class Chair extends Furniture { boolean hasWheels; String covering; Chair( boolean hasWheels, String covering ) { this.hasWheels = hasWheels;
this.covering = covering;
}//new Chair(true, "leather").price() -> 105.95 //new Chair(false, "leather").price() -> 88.95 //new Chair(true, "tweed").price() -> 49.95 //To report the price of this Chair double price() { // ... this.hasWheels ... this.covering ... if (this.hasWheels && this.covering.equals("leather") ) return 105.95; else if (this.covering.equals("leather") ) return 88.95; else return 49.95; } } abstract class List { } class Empty extends List { } class Larger extends List { Object first; List rest; Larger( Object first, List rest ) { this.first = first; this.rest = rest; } } |
abstract class EmployeeL { }
class EmptyEL extends EmployeeL { EmptyEL() { } } class LargerEL extends EmployeeL { Employee first; EmployeeL rest; LargerEL( Employee first, EmployeeL rest ) { this.first = first; this.rest = rest; } } abstract class Employee { abstract double salary(); } class Temp extends Employee { int hours; double rate; Temp( int hours, double rate) { this.hours = hours; this.rate = rate; } double salary() { return this.rate * this.hours; } } |
| /* +------------+ | Expression |<-----------------------+ +------------+ | +------------+ | / \ | --- | | | --------------------------------------- | | | | | +---------+ +-------------+ +------------------+ | | Num | | Variable | | Operation | | +---------+ +-------------+ +------------------+ | | int val | | String name | | String op | | +---------+ +-------------+ | Expression left |-+ | | Expression right |-+ | +------------------+ | | | | +--+ */ |