UML Exercise: Introduction to OOP Concept
Q1) Given the following incomplete code:
public
class House {
private String type;
private String address;
private int noOfRooms;
private double price;
public void setPrice(double price)
{
________________________________ (i)
}
public String getAddress()
{
_______________________________ (ii)
}
public double calcMonthlyPayment(int months)
{
//codes are not shown here
}
}//end
of House class
Draw a
UML class diagram representing the code.
|
House |
|
-type:
String -address:
String -noOfRooms:
Int -price:
double |
|
+setPrice(double)
: void +getAddress()
: String +calcMonthlyPayment(int)
: double
|
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) a)Draw
a UML class diagram for PressureCooker class.
b) b)Write a Java program for PressureCooker class.
|
PressureCooker |
|
model:
String size:
char colour:
String price:
double |
|
calculatePrice(int)
: double
|
private String
model;
private char size;
private String
colour;
private double
price;
public double calculatePrice (int quantity)
{
return price * quantity;
}
}
Comments
Post a Comment