0% found this document useful (0 votes)
122 views9 pages

Even Numbered Exercise Um L Diagram

The document describes several UML class diagrams representing different exercises involving class definitions. The class diagrams show classes, interfaces, attributes, methods, and relationships between classes. Specifically, it includes class diagrams for Stock, StopWatch, Fan, QuadraticEquation, Point, Tax, Rectangle2D, Date, Person hierarchies, Stack, ComparableCircle, and Rectangle.

Uploaded by

mastertkye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views9 pages

Even Numbered Exercise Um L Diagram

The document describes several UML class diagrams representing different exercises involving class definitions. The class diagrams show classes, interfaces, attributes, methods, and relationships between classes. Specifically, it includes class diagrams for Stock, StopWatch, Fan, QuadraticEquation, Point, Tax, Rectangle2D, Date, Person hierarchies, Stack, ComparableCircle, and Rectangle.

Uploaded by

mastertkye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Solutions for UML Class Diagrams

Chapter 9
Exercise 9.2: Stock
Stock
symbol: String

The symbol of this stock.

name: String

The name of this stock.

previousClosingPrice: double

The previous closing price of this stock.

currentPrice: double

The current price of this stock.

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.

Exercise 9.6: StopWatch


StopWatch

get methods for all da ta fields are provided a nd omitted for


bre vity.

-startTime: long
-e ndTime : long
+StopWa tc h()

Constructs a StopWatch object.

+start(): void

Starts the watch.

+stop(): void

Stops the watch.

+ge tElapsdTime(): long

Returns the elapsed time for the stop watc h in milliseconds.

Exercise 9.8: Fan


Fan
+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).

+Fan()

Constructs a fan with default values.

+getSpeed(): int

Returns the speed of this fan.

+setSpeed(speed: int): void

Sets a new speed for this fan.

+isOn(): boolean

Returns true if this fan is on.

+setOn(on: boolean): void

Sets this fan on to true or false.

+getRadius(): double

Returns the radius of this fan.

+setRadius(radius: double): void

Sets a new radius for this fan.

+getColor(): String

Returns the color of this fan.

+setColor(color: String): void

Sets a new color for this fan.

+toString(): String

Returns a string representation for this fan.

Exercise 9.10: QuadraticEquation


QuadraticEquation
-a : double

ge t methods for all data fields are provided and omitted for
brevity.
Thre e coefficients for the equation.

-b: double
-c : double
+QuadraticEquation(a : double, b:
double, c: double)

Constructs a QuadraticEquation with the specified


c oefficients.

+getDisc riminat(): double

Returns the discriminant of this equation.

+getRoot1(): double

Returns the first root of this equation.

+getRoot2(): double

Returns the se cond root of this e qua tion.

Chapter 10
Exercise 10.4: MyPoint

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.

Exercise 10.8: Tax


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

Exercise 10.12: MyRectangle2D

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

Exercise 10.14: MyDate


MyDate
-year: int
-m onth: int
-day: int

The year for the d ate.


The month for the date.
The day for the date.

+MyDate()

Con structs M yDate for the current d ate.

+MyDate(elaps edTime: long)


+getYear(): int

Con structs M yDate with a s pecified elapse time in milliseconds.

+getMonth (): int


+getDay(): int

Returns the month for the d ate.


Returns the day for the date.
Sets a new date using the elapsed tim e.

+setDate(elapsedTime: long): void

Returns the year for the date.

Chapter 11
Exercise 11.2: Person, Student, Staff, Employee
Person
Student

Employee
Faculty

Staff
Student

Person
-name: String

-status: String

-address: String

+Student()

-phone: String
-email: String
+Person()
+Person(name: String, address:
String, phone: String, email:
String)

+Student(name: String, address:


String, phone: String, email:
String)
+getStatus(): String
+setStatus(status: String): void
+toString(): String

+getName(): String
+getAddress(): String
+getPhone(): String
+getEmail(): String
+setName(name: String): void
+setAddress(address: String): void
+setPhone(phonee: String): void
+setEmail(email: String): void
+toString(): String

Faculty

Employee
-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)
+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

+getOfficeHour(): String

MyDate

Staff
-title: String

-year: int

+Staff()

-month: int

+Staff(name: String, address: String,


phone: String, email: String)

-day: int
+Faculty()

+getTitle(): String

+getYear(): int

+setTitle(title: String): void

+getMonth(): int

+toString(): String

+getDay(): int
+setYear(year: int): void
+setMonth(month: int): void
+setDay(day: int): void
+toString(): String

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.

Chapter 13
Exercise 13.6: ComparableCircle
interface
java.lang.Comparable<ComparableCircle>

Circle

ComparableCircle
+ComparableCircle(radius: double)
+compareTo(object: ComparableCircle): int

Exercise 13.10: Rectangle


interface
Comparable<Rectangle>
+compareTo(object: Rectangle): int

Rectangle

GeometricObject

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy