Professional Documents
Culture Documents
Sheet#2
Sheet#2
SAUD
UNIVERSITY
COLLEGE
OF
COMPUTER
AND
INFORMATION
SCIENCES
Computer
Science
Department
CSC
113:
Introduction
to
Programming
II Lab_Sheet#2
1nd
Semester
1442
<<Interface>>
Order
CakeHouse
- Name: String
1
..*
1
- NumOfCakes: int
+ CalculatePrice (): double
CakeList
+ Displayinfo():void + Cakehouse(name: String, size: int)
+ AddCake (in d: Cake): Boolean
+ GetTotalCost (): double
+ allWeddingCakes (Boolean: wfruit):
Cake {Abstract}
Cake[]
# Flavor: char +Print():void
# Size: char
+getCakeList(): Cake[]
+ Cake (flavor: char, size: char)
+ CalculatePrice (): double + get/set methods.
+ Displayinfo():void
WeddingCake
CupCake
- Withfruits:
boolean - Quantity: int
+ WeddingCake
(flavor: char, size: + CupCake (flavor: char, size:
char, withfruits:
boolean) char, quantity: int)
+ CalculatePrice (): double + CalculatePrice (): double
+ Displayinfo():void + Displayinfo():void
+ getWithfruits():boolean
Given the above UML diagram, write the complete java implementation for all the classes according to the
following description:
Cakehouse
1. Attributes:
• Name: a string to represent the bakery name.
• NumOfCakes: an integer to track the number of the desserts
2. Methods:
• Cakehouse (name: String, size: int) >> constructor to initialize the Cakehouse information.
• AddCake (in d: Cake): boolean >> adds the received object in the first empty location in the
CakeList array. The method returns true if the addition was successful and false otherwise.
• GetTotalCost (): double >> returns the total cost of the cakes.
• Print (): void >> Displays the information of the current object.
• getCakeList(): Cake [] >> returns the CakeList array.
• allWeddingCakes (boolean ): returns an array of all wedding cakes of that have fruit or not depend
on the received value from parameter.
Cake
1. Attributes:
• Flavor: a char to represent cake flavor: V for Vanilla, C for Chocolate and P for Peanut butter.
• Size: a character to represent dessert size where S for small, M for medium, and L for large size.
2. Methods:
• Cake (flavor: char, size: char) >> constructor to initialize flavor and size with the received
parameters.
• CalculatePrice (): double >> this is an abstract method returns price of the cake.
• Displayinfo (): void >> this is method that displays the cake’s information.
WeddingCake
1. Attributes:
• Withfruits: a boolean (true or false) to indicate whether the wedding cake includes fruits or not.
2. Methods:
• WeddingCake (flavor: char, size: char, withfruits: boolean) >> constructor to initialize flavor,
size, and withfruits with the received parameters.
• CalculatePrice (): double >> calculates the price of the wedding cake based on its size:
S costs 60 SR
M costs 100 SR
L costs 120 SR
There is an extra 30 SR for adding fruits.
• Displayinfo (): void >> this is a method that displays the cupcake’s information.
• getWithfruits(): Boolean>> get method that return a Boolean value of withfruits attribute
CupCake
1. Attributes:
• Quantity: an integer to indicate the quantity of cupcakes.
2. Methods:
• CupCake (flavor: char, size: char, quantity: int) >> constructor to initialize flavor, size, and
quantity with the received parameters.
• CalculatePrice (): double >> calculates the price of the cupecake based on its size and quantity:
S costs 8 SR for one piece.
M costs 12 SR for one piece.
• Displayinfo (): void >> this is a method that displays the cupcakes’s information.
TestCakehouse
Finally, implement TestCakehouse class with main method to do the following tasks:
o Create a CH cake object name it “Cake House” and can have a maximum 50 of cakes.
o Then display the following menu until the user choose to exit:
1. Add a new cake( WeddingCake or CupCake):
- Ask the user to choose between adding a WeddingCake or CupCake.
- Prompt the user to enter all the required information based on that.
- Display a meaningful message reflecting the success of the addition.
2. Display the information of the CH bakery.
3. Find list of all wedding cakes with specific value of with fruit or without fruit
(true/false).
4. Print the total cost of the order.
5. Exit.
IMPORTANT NOTE: Make sure you use the same variable, method and class names as
shown in the UML. Not doing so will affect your mark.