Question: JAVA The source code below defines a Customer class. Examines the code and answer the questions below; public class Customer extends Person implements Comparable {
JAVA
The source code below defines a Customer class. Examines the code and answer the questions below;
public class Customer extends Person implements Comparable
private float totalSpent;
public Customer(String id, String name, float totalSpent){
super(id, name);
this.totalSpent = totalSpent;
}
public int compareTo(Customer customer) {
int x = this.name.compareTo(customer.name);
if (x == 0){
return 0;
}else if(x < 0){
return 1;
}else{
return -1;
}
}
public float getExpenditure(){
return totalSpent;
}
}
Using ArrayList, write a simple program to create five customer objects. The details of the objects should be entered through a console by prompting the user. (5 marks)
The current implementation of the compareTo() method enables the program to order customers details in descending order, based on their names. Rewrite the method to enable the program to order the details in ascending order, based on the total amount a customer spend.
Write a method that calculates a discount of 20% from the amount of the customer who spent most.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
