CSE 1100 ASSIGNMENT #5 Spring 2017 Due: Friday, March 24th Maximum points: 20 Im
ID: 3803786 • Letter: C
Question
CSE 1100 ASSIGNMENT #5 Spring 2017 Due: Friday, March 24th Maximum points: 20 Important: This is an individual assignment. Please do not collaborate. Make that you write everyline ofyour code. Using code writtembusomeomeelsemiLbeconsidemda yiolation ofthe academic integriozand wiLnesultina mportBethe Deanketzior. What This Assignment Is About: Implementing classes Understanding and accessing instance variables Implementing methods Object construction Use the following Coding Guidelines: Give identifiers semantic meaning and make them casy to read (examples numStudents, grossPay, etc). User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. is to create a file called Customerjava containing a class Customer (there is no main method in this class) A Customer has a first name (a String), last name (String), ID number (integer), number of larger drinks (integer, number of small drinks (integer. and total cost (double). Each large drink costs S8.50 and each small drink costs s4es0. You Deed to compute the total cost based on the number of large drinks and small drinks The class Customer must include the following constructors and methods. (fyour class does not contain any of the following methods, points will be deducted,) on of the MethodExplanation / Answer
Here is the Customer.java class. Assignment5.java is not provided. So, please use this class and compile to see your output. Let me know if anything goes wrong.
PROGRAM CODE:
package customer;
//Customer class
public class Customer {
private String firstName;
private String lastName;
private int customerID;
private int largeDrinks;
private int smallDrinks;
private double totalCost;
//Default constructor
public Customer() {
firstName = "???";
lastName = "???";
customerID = 0;
largeDrinks = 0;
smallDrinks = 0;
totalCost = 0.0;
}
//parameterized constructor
public Customer(String lname, String fname, int id, int largeDrinks, int smallDrinks)
{
firstName = fname;
lastName = lname;
customerID = id;
this.largeDrinks = largeDrinks;
this.smallDrinks = smallDrinks;
totalCost = 0.0;
}
//getters and setters
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getCustomerID() {
return customerID;
}
public void setCustomerID(int customerID) {
this.customerID = customerID;
}
public int getLargeDrinks() {
return largeDrinks;
}
public void setLargeDrinks(int largeDrinks) {
this.largeDrinks = largeDrinks;
computeTotalCost();
}
public int getSmallDrinks() {
return smallDrinks;
}
public void setSmallDrinks(int smallDrinks) {
this.smallDrinks = smallDrinks;
computeTotalCost();
}
public double getTotalCost() {
return totalCost;
}
@Override
public boolean equals(Object obj) {
Customer cust = (Customer) obj;
if(this.customerID == cust.customerID && this.lastName.equals(cust.lastName) && this.firstName.equals(cust.firstName))
return true;
else return false;
}
private void computeTotalCost()
{
for(int i=0; i<largeDrinks; i++)
{
totalCost += 8.50;
}
for(int i=0; i<smallDrinks; i++)
{
totalCost += 4.50;
}
}
public Customer hasMore(Customer other)
{
if(this.totalCost == other.totalCost || this.totalCost > other.totalCost)
return this;
else return other;
}
@Override
public String toString() {
String result = " First name: " + firstName;
result += " Last name: " + lastName;
result += " Customer ID: " + customerID;
result += " Number of Large Drink(s): " + largeDrinks;
result += " Number of Small Drink(s): " + smallDrinks;
result += " Total cost: $" + totalCost;
return result;
}
}