Professional Documents
Culture Documents
Chapter 8
Stock(symbol: String, name: String) Constructs a stock with a specified symbol and a name.
getChangePercent(): double Returns the percentage of change of this stock.
+SLOW = 1 Constant.
+MEDIUM = 2 Constant.
+FAST = 3 Constant.
-speed: int The speed of this fan (default 1).
-on: boolean Indicates whether the fan is on (default false).
-radius: double The radius of this fan (default 5).
-color: String The color of this fan (default white).
1
ge t methods for all data fields are provided and omitted for
QuadraticEquation brevity.
2
Chapter 10
MyPoint
-x: double x-coordinate of this point.
-y: double y-coordinate of this point.
+MyPoint() Constructs a Point object at (0, 0).
+MyPoint(x: double, y: double) Constructs an object with specified x and y values.
+getX(): double Returns x value in this object.
+getY(): double Returns y value in this object.
+distance(secondPoint: MyPoint): double Returns the distance from this point to another point.
+distance(p1: Point, p2: MyPoint): double Returns the distance between two points.
Tax
-filingStatus: int
-brackets: int[][]
-rates: double[]
-taxableIncome: double
+Tax()
+Tax(filingStatus: int, brackets: int[], rates: double[],
taxableIncome: double)
+getFilingStatus(): int
+setFilingStatus(filingStatus: int): void
+getBrackets(): int[][]
+setBrackets(brackets: int[][]): void
+getRates(): double[]
+setRates(rates: double[]): void
+getTaxableIncom(): double
+setTaxableIncome(taxableIncome: double): void
+getTax(): double
3
M yRectangle2D
-x: double
-y: double
-width: double
-height: double
+MyRectangle2D()
+MyRectangle2D(x: double, y: double, width: double,
height: double)
+getX(): double
+setX(x: double): void
+getY():double
+setY(y: double): void
+getWidth(): double
+setWidth(width: double): void
+getHeight(): double
+setHeight(height: double): void
+getRadius(): double
+getPerimeter(): double
+getArea(): double
+contains(x: double, y: double): b oolean
+contains(r: Rectangle2D): boolean
+overlaps(r: Rectangle2D): boolean
4
Chapter 11
5
Exercise 11.2: Person, Student, Staff, Employee
Person
Student Employee
Faculty Staff
Person Student
-name: String -status: String
-address: String +Student()
-phone: String
+Student(name: String, address:
-email: String String, phone: String, email:
+Person() String)
Employee Faculty
-office: String -officeHour: String
-salary: int -rank: String
-dateHired: java.util.Date +Faculty()
+Employee() +Faculty(name: String, address: String,
phone: String, email: String)
+Employee(name: String, address:
String, phone: String, email: String) +getOfficeHour(): String
+getOffice(): String +setOfficeHour(officeHour: String): void
+getSalary(): int +getRank(): String
+getDateHired(): Date +setRank(rank: String): void
+setOffice(office: String): void +toString(): String
+setSalary(salary: int): void
+setDateHired(dataHired: Date): void
+toString(): String
6
Staff MyDate
-title: String -year: int
+Staff() -month: int
-day: int
+Staff(name: String, address: String,
phone: String, email: String) +Faculty()
7
Exercise 11.10: MyStack
MyArrayList
MyStack
+isEmpty(): boolean Returns true if this stack is empty.
+getSize(): int Returns the number of elements in this stack.
+peek(): Object Returns the top element in this stack.
+pop(): Object Returns and removes the top element in this stack.
+push(o: Object): Object Adds a new element to the top of this stack.
+search(o: Object): int Returns the position of the first element in the stack from
the top that matches the specified element.
8
Chapter 15
Exercise 15.8: ComparableCircle
«interface» Circle
java.lang.Comparable
ComparableCircle
+ComparableCircle(radius: double)
+compareTo(object: Object): int
9
Exercise 15.12: Rectangle
«interface»
Comparable
+compareTo(object: Object): int
GeometricObject
Rectangle
10