Exercise UML
School of
Computing, UUM College of Arts and Sciences
STIA1123 PROGRAMMING 2
Exercise : Introduction to OOP Concept
1. Given the
following incomplete code:
Draw a
UML class diagram representing the code.
|
House |
|
-houseType : String -houseAddress : String -housenoOfRooms : int -housePrice : double |
|
+ setPrice(double): void + getAddress()
:String + calculateMonthlyPayment(int): double |
2. Based on the following scenario, answer
the following questions:
You are appointed to develop a
program for Philipsi Pressure Cooker company. The program should keep
information about the
pressure cooker which includes String for model (e.g. HD2139, RL1198, BF2222,
EPC-6000s), char for size (e.g. L
(large), M (medium), S (small)), String for colour (brown,
silver, golden, white) and double for price (e.g. RM309.00, RM169.00,
RM399.00, RM270.48). There will be a method in the PressureCooker class, named calculatePrice(). This method receives ONE (1) parameter: an int type variable named quantity. The method returns price, which is
of type double. For this
purpose, a class named PressureCooker
has
to be defined.
a) Draw
a UML class diagram for PressureCooker class.
|
PressureCooker |
|
-pressureCookerModel:
String -pressureCookerSize:
char -pressureCookerColour:
String -pressureCookerPrice:
double |
|
+CalculatePrice(int)
: double |
a) Write a Java program
for PressureCooker class.
|
public
class PressureCooker { private String model; private String colour; private char size; private double price; public double calculatePrice (int quantity) {
Return price * quantity; } }//end
of PressureCooker class |

Comments