Write a customer class that minimally stores the following data fields for a cus
ID: 3789944 • Letter: W
Question
Write a customer class that minimally stores the following data fields for a customer:
–Name
–Customer phone number
–Total amount of purchase
–Time duration of membership by month
The following methods should also be provided:
–A constructor that initializes the name and phone number
–A method that returns the customer name field
–A method that returns the customer phone number
–A method that determines if two customer objects are equal if their name and phone number are the same
–Methods to retrieve the total amount of purchase
–Methods to update the total amount of purchase if a new purchase has been placed by the customer
–Method to set and retrieve the time duration of membership by month
Explanation / Answer
HI, Please find my implementation.
please let me know in case of any issue.
public class Customer {
// instance variables
private String name;
private String phoneNumber;
private double purchaseAmount;
private int duration;
// constructor
public Customer(String name, String phone) {
this.name = name;
this.phoneNumber = phone;
purchaseAmount = 0;
duration = 0;
}
public String getName(){
return name;
}
public String getPhoneNumber(){
return phoneNumber;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Customer){
Customer cust = (Customer)obj;
if(name.equals(cust.name) && phoneNumber.equals(cust.phoneNumber))
return true;
}
return false;
}
public double getPurchaseAmount(){
return purchaseAmount;
}
public void setPurchaseAmount(double amt){
purchaseAmount = amt;
}
public int getDuration(){
return duration;
}
public void setDuration(int d){
duration = d;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.