CSE 110 ASSIGNMENT NS Spring 2017 Due: Friday, March 24th Maximum points: 20 Imp
ID: 3803793 • Letter: C
Question
CSE 110 ASSIGNMENT NS Spring 2017 Due: Friday, March 24th Maximum points: 20 Important: This is an individual assignmenL Please do nar collaborate. What This Assignment Is About: Implementing classes Understanding and accessing instance variables Implementing methods Encapsulation Use the following Coding Guidelines Give identifiers semantic meaning and make them casy to read (examples numStudents, grossPay, cte), User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all edheridentifiers (variables, methods, objects. Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, andcode associated th if, switches and loops Beconsistent with the number of spaces or tabsthat you use to indent. Use white space to make your program more readable. Part 2 Chere is no part this assignmentyrregrammiegao polats) Your assignment isto create file called Customerjava containing aclass Customer (there is no main method in this class), ACustomer has a first name a String), last name (String). IDnumber (nteger.number of larger drinks (integer), number of small drinks (integer), and total cost double Each large drinkcosts S&50 and each small drink costsS 50.You need to computethe total cost based on the number of large drinks and small drinks. The class Customer must include the following constructors and methods Ir your class does not contain any of the following methods, points will be doducted.) Method Descriptiee Method Default constructor sets the first name and last name to rm customer ID the public Customer() of large drinks, and the tumber of small drinks to 0, andthe total cost to Customer (String iname, String Customer objokt given te last name,first name, customer id, theExplanation / Answer
Here is the code :
class Customer {
String firstname;
String lastname;
int CustomerID;
int LargeDrinks;
int SmallDrinks;
double TotalCost;
//constructor method
Customer() {
firstname= "???";
lastname=" ???";
CustomerID=0;
LargeDrinks=0;
SmallDrinks=0;
TotalCost=0.0;
}
Customer(String lname,String fname,int id,int largeDrinks, int smallDrinks){
firstname=fname;
lastname=lname;
CustomerID=id;
LargeDrinks=largeDrinks;
SmallDrinks=smallDrinks;
}
public String getFirstName(){
return firstname;
}
public String getLastName(){
return lastname;
}
public int getCustomerID(){
return CustomerID;
}
public int getLargeDrinks(){
return LargeDrinks;
}
public int getSmallDrinks(){
return SmallDrinks;
}
public double getTotalCost(){
return TotalCost;
}
public void SetFirstName(String fname){
firstname=fname;
}
public void setLastName(String lname){
lastname=lname;
}
public void setCustomerID(int id){
CustomerID=id;
}
public void setLargeDrinks(int largenum){
LargeDrinks=largenum;
}
public void setSmallDrinks(int smallnum){
SmallDrinks=smallnum;
}
public boolean equals(Customer other){
return(this.firstname==other.firstname && this.lastname ==other.lastname && this.CustomerID==other.CustomerID);
}
private void computeTotalCost(){
this.TotalCost = 4.50*getSmallDrinks() + 8.50*getLargeDrinks();
}
public Customer hasMore(Customer other){
this.computeTotalCost();
other.computeTotalCost();
if (this.TotalCost < other.TotalCost){
return other;
}
else if(this.TotalCost > other.TotalCost){
return this;
}
else {
return this;
}
}
public String toString(){
return "First name: " + getFirstName() + " " + "Last name: "+ getLastName() + " " + "Customer ID: " + getCustomerID() + " " +"Number of Large Drink(s): " + getLargeDrinks() + " " + "Number of Small Drink(s):" +getSmallDrinks() +" "+ "TotalCost: $" +getTotalCost();
}
public static void main(String[] args) {
Customer cust1 = new Customer(); //default Constuctor
System.out.println(cust1); // Display Cust1
Customer cust2 = new Customer("jaff","godge",12345,12,5); // Constructor with parameter
System.out.println("first name: "+ cust2.getFirstName());
System.out.println("last name: " + cust2.getLastName());
System.out.println("Customer ID: " + cust2.getCustomerID());
System.out.println("no of large Drink(s): " + cust2.getLargeDrinks());
System.out.println("no of Drinks(s): " +cust2.getSmallDrinks());
if (cust1.equals(cust2))
{
System.out.println("both are same "); // comparison
}
else {
System.out.println("both are different"); // comparison
}
System.out.println(cust1.hasMore(cust2)); // whose total cost is more?
}
}
sample output :
First name: ???
Last name: ???
Customer ID: 0
Number of Large Drink(s): 0
Number of Small Drink(s):0
TotalCost: $0.0
first name: godge
last name: jaff
Customer ID: 12345
no of large Drink(s): 12
no of Drinks(s): 5
both are different
First name: godge
Last name: jaff
Customer ID: 12345
Number of Large Drink(s): 12
Number of Small Drink(s):5
TotalCost: $124.5