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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started