Exercise OOP Concept
School of Computing, UUM College of Arts and
Sciences
STIA1123 PROGRAMMING 2
Lab Exercise : Introduction
to OOP Concept
1. Given the following UML Class diagram:
|
Bike |
|
-bikeColor : String -bikePrice : double |
|
+getBikeColor(String): String +calculateMonthlyPayment(): double +getBikePrice(String): double +printBikeInfo(): void
|
a) Identify
o
Class name: bike
o
Object: bicycles
&motorcycles
o
Attributes and its
data types: color: String , Price: double
o Methods: getBikeColor (String), calculateMonthlyPayment(), getBikePrice(String), printBikeInfo()
b) Determine the types of method and the data types of values returned.
1. GetBikeColor() is a value returning method and will return a String value
2. PrintBikeInfo() is void method and no value will be return
2. You are required to write a simple Java program that can prompt a user to enter radius of a sphere, computes the volume and area of sphere, then displays its result by using OOP concept. Answer the following questions as an initial step of solving the problem:
a) Identify the object (s) involved in this problem.
Sphere
b) List down all related the attribute(s) and method(s) of each identified
object.
Attributes:
radius, volume and area
Methods:
computeVolume(), computeArea() and displayVolumeAre()
DisplayResult()
c) Draw the UML class diagram from the answer of question 2(b).
|
Sphere |
|
-radius: double -volume: double -area: double |
|
+computeVolume() +computeArea() +displayResult() |
a)
Identify the object (s) involved in this problem.
b) List down all related the attributes and methods of each identified object.
Attributes: employee
id, name, position, department, address, monthly total hours work, sale volume
per month
Methods: displayEmployeeID(),
displayName(), displayPosition, calculateMonthlySalary(),
calculateTotalHoursWork()
c)
Draw the UML class diagram from the answer of
question 3(b).
|
Employee |
|
-employeeID:
double -employeeName:
String -employeePosition:
String -employeeDepartment: -employeeAddress: -employeeMonthlyTotalHoursWork:
double -employeeSaleVolumePerMonth:
double
|
|
+addingEmployeeInformation() +calculateTotalHoursWorks() +displayEmployeeDetails() |
|
a) Identify the object (s) involved in this problem
Donuts
b) List down all related the attributes and methods of each identified
object.
Attributes: donuts
type, topping, size and price
Methods: displayDonutsType(),
displayDonutsTopping(), displayDonutsSize(), calculateDonutsPrice ()
c) Draw the UML class diagram from the answer of question 4(b).
|
Donut |
|
-DonutsType: String -DonutsTopping:
String -DonutsSize:String -DonutsPrice: double |
|
+addingDonutsInformation() +calculateDonutsPrice() +displayDonutsDetails() |
5. Draw the UML class diagram from the following description.
A
library is planning to develop a library information system. This library will
serve only registered students. Each book has title, author,
publisher, date-of-publication, ISBN number and a set of keywords. Each
student has SSN, first name, last name, address, and telephone number.
A student can borrow a book for up to two weeks, so it is necessary to keep
track of the date-of-borrow. He can then renew the book for another two weeks.
Two renewals are allowed. After two renews, the student must return a borrowed
book. If a book is overdue, the student must pay a fine of RM0.50 a day.
|
Book |
Student |
BookLoan |
|
bookTitle bookauthor bookpublisher bookdateOfPublication bookISBNNumber bookKeywords |
studentSSN studentFirstName studentLastName studentAddress studentNumber |
student: student book: Book borrowingDate returningDate |
|
|
|
borrowBook() returnBook() calculateFine() |
6. Draw an inheritance hierarchy for these
three classes, Staff, Student and Person.


Comments