Question
add a method listAccounts () that will display information about each Customer in the collection of Customer you maintained in your class PaperRoute use the
- add a method listAccounts() that will display information about each Customer in the collection of Customer you maintained in your class PaperRoute
- use the Comparable interface so that when you ask to list the Customers, the list will be displayed with the Customers that owe the most money shown first (i.e., in descending order), and then by alphabetical name. [So we'd say list will be sorted amountDue descending, name ascending.]
- Hints:
- Of course, if Customer is Comparable, it will need a compareTo() method
- We will want to use sort(.) to change the order of the ArrayList: youll need to use the name of your ArrayList.
Customer.java
public class Customer{
private String name;
private String streetAdress;
private String city;
private boolean getsDaily;
private boolean getsSunday;
private double amountDue;
public Customer(String name, String streetAdress, String city, boolean getsDaily, boolean getsSunday,
double amountDue) {
super();
this.name = name;
this.streetAdress = streetAdress;
this.city = city;
this.getsDaily = getsDaily;
this.getsSunday = getsSunday;
this.amountDue = amountDue;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStreetAdress() {
return streetAdress;
}
public void setStreetAdress(String streetAdress) {
this.streetAdress = streetAdress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public boolean isGetsDaily() {
return getsDaily;
}
public void setGetsDaily(boolean getsDaily) {
this.getsDaily = getsDaily;
}
public boolean isGetsSunday() {
return getsSunday;
}
public void setGetsSunday(boolean getsSunday) {
this.getsSunday = getsSunday;
}
public double getAmountDue() {
return amountDue;
}
public void setAmountDue(double amountDue) {
this.amountDue = amountDue;
}
@Override
public String toString() {
return "Customer [name=" + name + ", streetAdress=" + streetAdress + ", city=" + city + ", getsDaily="
+ getsDaily + ", getsSunday=" + getsSunday + ", amountDue=" + amountDue + "]";
}
}
PaperRoute.java
import java.util.ArrayList;
import java.util.Collections;
public class PaperRoute{
private ArrayList
public PaperRoute() {
customerList = new ArrayList
}
public void addCustomer(String name, String streetAddress, String city, boolean getsDaily, boolean getsSunday, double amountDue) {
customerList.add(new Customer(name, streetAddress, city, getsDaily, getsSunday, amountDue));
}
public int totDue() {
int total = 0;
for(Customer c : customerList) {
total += c.getAmountDue();
}
return total;
}
public void displayAll() {
for(Customer c : customerList) {
System.out.println(c);
}
}
public int countBySubscriptionType(String kind) {
int count = 0;
for(Customer c : customerList) {
if(c.isGetsDaily()==true) {
count +=1;
}
}
return count;
}
}
Main.java
public class Main {
public static void main(String[] args) {
PaperRoute myRoute = new PaperRoute();
myRoute.addCustomer("Henry", "43 Comet Rd", "Heaven", true, false, 90);
myRoute.addCustomer("Gio", "10 Toy Lane", "Mutty", false, true, 10);
myRoute.addCustomer("Matt", "89 Farfield Rd","Kitty",false, true, 110);
myRoute.addCustomer("Tony", "92 Mclaren Ln", "Rusk", true, false, 85);
System.out.println("Total value: " + myRoute.totDue());
myRoute.displayAll();
System.out.println("Who Has a Daily Subscription " + myRoute.countBySubscriptionType("2004A"));
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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