Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Working on a java 8 program that reads in files of people information (name, inc

ID: 3831073 • Letter: W

Question

Working on a java 8 program that reads in files of people information (name, income, county, state, zip). The end result of the program is to print the list of appropriate values (only information belonging to a certain state) in the following format: First Name, Last Name, Relative Income, County. But in descending order of Relative Income

I have it printing this information with the following statement:

However I am completely stuck how to go about sorting it just by the relative income (also no for or while loops allowed in the code)

Also I can show more code but was trying to keep it as short as possible.

Explanation / Answer

Hi friend, you can first sort peopleList in decending order by Income.
For that youe People calss can implement Comparable interface.
While extending Comparable interface, you need to override compareTo method when you write ligic based in income.
After that you can use: Colleactions.sort(peopleList); to sort them

After that you can print the list


peopleList.forEach((p) -> System.out.println(p[0] + " " + p[1] + " " + (Integer.parseInt(p[2]) - avgIncome) + " " + line[0]));

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote