Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package week_5; import java.util.ArrayList; /** There is a file called recycling-report-main-street.txt in the root directory of this project. This file contains data for a much

package week_5; import java.util.ArrayList; /**   There is a file called recycling-report-main-street.txt in the root  directory of this project.   This file contains data for a much longer street. Again, the house numbers correspond to array or ArrayList indexes.  Read it into your program, analyze the data, and then display the numbers of the house(s) that recycled the most crates?   Make sure you use try-catch blocks for IOException.   */  public class Question_3_Read_Recycling_Report { String filename = "recycling-report-main-street.txt"; public static void main(String[] args) { new Question_3_Read_Recycling_Report().recyclingReport(); } public void recyclingReport(){ // Read the file into ArrayList lines = readLinesFromRecyclingDataFile(filename); ArrayList crateQuantities = extractCrateQuantityData(lines); int max = calculateMax(crateQuantities); ArrayList housesWithMax = copyIndexesToNewArrayList(crateQuantities, max); System.out.println("The maximum number of crates is " + max); System.out.println("The houses with this max number of crates is " + housesWithMax); } public ArrayList readLinesFromRecyclingDataFile(String filename) { // TODO read the lines of the file, given by filename, into an ArrayList.  // Don't modify the lines. Each element in the ArrayList is one line from the file. // Return the ArrayList. return null; } public ArrayList extractCrateQuantityData(ArrayList lines) { //TODO extract the number of crates from each String,  // convert to an integer, and save each integer in a new ArrayList return null; } public int calculateMax(ArrayList crates) { // TODO calculate the largest value in the crates ArrayList, and return it  // Example: if the ArrayList contains [ 9, 3, 2, 5, 9, 0 ], you should return 9. // Make this method general, so it works for any set of numbers. // If the ArrayList contains [-9, -4, -2, -10] this function should return -2. return 0; } public ArrayList copyIndexesToNewArrayList(ArrayList quantities, int value) { //TODO finish this method so it writes the indexes of the houses with the max value into a new ArrayList,  //and return the ArrayList. // This should be a generic method to copy all of the indexes of an ArrayList // where the element holds a certain value; into a new ArrayList. // Example: if the ArrayList contains [ 9, 3, 2, 5, 9, 0 ] // The maximum values, 9, is found at index 0 and 5 // So create and return a new ArrayList that contains [ 0, 5 ] return null; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

=+1. Determine the purpose.

Answered: 1 week ago

Question

trans european transport network

Answered: 1 week ago

Question

4 2 6 .

Answered: 1 week ago