You are on page 1of 3

DEPARTMENT OF COMPUTER SCIENCE

UW
Assigned Date: 30-10 – 19
ASSIGNMENT 2

Discipline/Semester: BSCS 3RD


Course Code: CS-212 Due Date: 06- 11 - 19
Course : Advanced Object Oriented Programming
Total Marks: 10
Note: Plagiarized assignments will be marked zero. Continuous plagiarism will result in negative
marking.

You need to write code for a Salon Service. For better customer management the Salon has divided
the customers into two classes; Customer and PremiumCustomer. The track of ordinary customers in
not maintained whereas the premium customers have a maintained history. Premium customer are
also able to get a discount of 20% in each purchase.

Remember the Customer class can only have one Visit object while a PremiumCustomer can have
more than one Visit objects.

Write code for class Visit. The class has:

 Variables: date, serviceCharges, productCharges


 Functions:
 A constructor that sets all the variables
 Setter and getter for each variable
 A function toString that returns the value of variables in a similar format :
Date: 10\11\2011
Service Charges: 200.0
Product Charges: 300.0

Write code for class Customer. The class has:

 Variables: name, a Visit class object.

Hint: You will need an ArrayList of Visit type objects “visitList”

Remember:
The Customer class can only have one Visit object. For Customer the size of this list cannot be
greater than zero.
 Functions:
 A constructor(String name,Visit v)
 Setter and getter for all variables
 getTotalExpense(): return serviceCharges+productCharges
 toString(): return the message in the following form
Customer Name:Farrah
MemberShip:Customer No of visit:1
Date:10\11\2011
Service Charges: 200.0
Product Charges: 300.0
 printBill(): print the bill in a similar form.
Hint: You must use already created functions of toString
Customer Name:Farrah
MemberShip:Customer No of visit:1
Date:10\11\2011
Service Charges: 200.0
Product Charges: 300.0
Total:500.0

Write code for class PremiumCustomer. The class is a subtype of Customer class and Discountable
interface. You can use the following interface :

public interface Discountable {


static final double premiumDiscountRate=0.20;
double discount(double amount);
}
The class has:

 Functions:
 A constructor that sets all variables.
 addVisit(Date d1,double serviceCharges, double productCharges):
add a Visit type object to the “visitList” with the
 getTotalExpense(): Get the values from the last element of visitList and calculate
Total . Then call the function discount (total) to return the remaining total.
 Discount(double total): deduct 20% from the total and return it.
 getCustomerHistory():
Iterate over all the list and call toString of all visit object
for(Visit i : super.visit){

}
 getTotalNoOfVisit(): return the size of visitList.
 printBill(): Prints the bill in the following format:
Hint: You need to use the functions from the parent class for printing the message
Customer Name:Aslam
MemberShip:PremiumCustomer No of visit:2
Date:10\11\2011
Service Charges: 400.0
Product Charges: 200.0
Write code for the testClass

 Create an object of Date , Visit and then use it to create an object c1 of Customer class.
 Call the printBill method over c1.
 Create an object of Date , Visit and then use it to create an object of PremiumCustomer class
p1.
 Call printBill method over p1.
 Add a visit to p1 and call printBill again.
 Call printCustomerHistory of p1.

Output can be similar to the following figure:

You might also like