Java Eclipse

HW03-1: Enhance PaperRoute•
In Eclipse Project Explorer, copy your HW02 project (PaperRoute) to a new project using
this technique:
1.
2.
3.
4.
Open the completed HW02 (PaperRoute) project.
right-click on project name, and then click “copy”
right-click in the list of projects then click “paste”
In dialog box that should pop up, change name of new project to
HW03WeissmanSorted [use your own name!]

Revise the project accordingly to
▪ 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:
1. Of course, if Customer is Comparable, it will need a compareTo() method
2.
We will want to use Collections.sort(….) to change the order of the
ArrayList: you’ll need to use the name of your ArrayList.
3.
Be sure you have test data that will demonstrate the effectiveness of your
sort by changing the original order of data displayed
Deliverable: Be sure there is a Javadoc comment disclosing any and all collaboration you did to
complete this assignment. Attach the usual — zip of Eclipse project directory, plus Word doc or
individual; files with screen shot(s) of test run(s).
Upload file(s) as needed, and use “Comment” textbox as needed to disclose any known
defects.
HW 3-1 Enhance Paper Route Comparable
9/17/2022 9:48 AM
Some hints for the “Enhance Paper Route” Assignment….
The idea is to add a sort of Customer descending by amountDue, ascending by name. There are
a few mechanical issues you’ll have to solve as well, but the heart of this is to add a
compareTo(…) method to Customer, and make Customer implement Comparable. So far, I
hope I haven’t told you anything new!
Here are some thoughts on writing int compareTo(…)
My approach was to make a math problem of the sort by amountDue. Examples as pseudo code:
int compare = this.amount – other.getAmount(); //ascending
int compare = other.getAmount() – this.amount; //descending
BUT, amountDue is double, so in the above code, you’d need to make the “compare”
variable double
BUT, compareTo() must return int. So, in the end cast your “compare” as (int). Example
return (int) compare;
If the numeric comparison is zero [equal], the secondary sort is by name, using the built-in
compareTo() of class String. And there would be an else clause, similar to the class Book
example in my slides. The tricky thing here would be to capture the int result from this compare
and maybe assign to your “compare” variable — or perhaps just return in the else branch
immediately.
Well, even though this sounds very complicated, my test routine wound up as about six lines
of code, not counting the header and curly braces I coded on separate lines.
————–Here’s an alternate solution employed by several of my students:
Alternative logic (pseudo-code):
if( amtDue > other.getAmtDue())
return -1;
etc…
if ==, return the name compare result
In writing the above approach, one student used a variable like “compare”, and the other just did
three different return statements inside logical branches, as illustrated above.
FINALLY, here’s a third approach:
Both the Integer class and the Double class have a compareTo() method built in.
Example of usage, just to get you started – but look up details in java api and/or THINK!!
int compare = ((Double) this.getAmountDue()).compareTo(other.getAmountDue());

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER