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
|
o Class name: Bike
o Object: bicycle, moto, etc
o Attributes and its data types: bikeColor : String, bikePrice: double
o Methods: Method to get bike color, to calculate monthly payment, to get bike price, to print bike info
b) b) Determine the types of method and the data types of values returned.
-getBikeColor,
value returning method, string is returned
-calculateMonthlyPayment
is a value returning method
-
getBikePrice is a value returning method and string is returned
-printBikeInfo is a void method and no data is returned
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 displayVolumeArea()//split display//displayResult
c) Draw the UML class diagram from the answer of question 2(b)
|
Sphere |
|
radius: volume:
area: |
|
computeVolume()
: computeArea()
: displayVolumeArea()
:
|
Q3) You are a new programmer appointed for a company named HoneyB Corporation. The company requires a new system to manage employees’ information. Each employee has his/her employee id, name, position, department, address, monthly total hours work and sale volume per month. Among the related initial functions to take into consideration are: adding each employee’s information, calculate monthly salary and display each employee’s details.
a) Identify the object (s) involved in this problem.
employee
b) List down all related the attributes and methods of each identified
object.
Attributes: id, name, position, department, address, monthly total hours work, sale volume per month
Methods:
addEmployeeInfo, calculateMonthlySalary, displayEmployeeInfo
c)
Draw the UML class diagram from the answer of
question 3(b).
|
Employee |
|
id: name: position: department: address: monthlyTotalHoursWork: saleVolumePerMonth: |
|
addEmployeeInfo()
: calculateMonthlySalary()
: displayEmployeeInfo()
: |
Q4) You are appointed to develop a program for Donkey Donuts. The program should keep information about the donut which are type, topping, size and price. Additionally, the program also should be able to calculate the price of donuts and display the bill.
a) Identify the object (s) involved in this problem.
Donut
b) List down all related the attributes and methods of each identified object.
Attributes: type, topping, size, price
Methods: calculateDonutPrice, displayBill
c)
Draw the UML class diagram from the answer of
question 4(b).
|
Donut |
|
type: topping: size: price: |
|
calculateDonutPrice()
: displayBill()
: |
Q5) 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 |
|
title: author: publisher: date-of-publication: numberISBN: keywords: |
|
publishBook()
: computeArea()
: displayVolumeArea()
:
|
|
Student |
|
ssn: firstName:
lastName: address: telephoneNumber: |
|
registerStudent()
: borrowBook()
:
|
|
Lending
System |
|
dateOfBorrow: numOfRenewal:
returnStatus: |
|
computeDueDate()
: computeRenewalTime()
: computeFine(): displayTotalFine()
:
|
Q6) Draw an inheritance hierarchy for these three classes, Staff, Student and Person.
Comments
Post a Comment