Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FRQ: Air Quality Analyzer. PLEASE COMPLETE MAIN CLASS, THANK YOU! Your code should use ArrayLists instead of Arrays. Provided in your starter code is a

FRQ: Air Quality Analyzer. PLEASE COMPLETE MAIN CLASS, THANK YOU!

Your code should use ArrayLists instead of Arrays.

Provided in your starter code is a City.java class with the name of the city and the pmValue for the city as private instance variables. The class also provides constructors (default and parameter) and get() methods for the instance variables and a loadValues() and a toString() method.

In the starter code you will see multiple places where you will need to write additional code. Make sure you write the implementation code for:

  • In the City.java class, you will need to change the city names and the pmValues from the sample values provided. Use the data set (A) provided to you by your teacher for your values.
  • main() method should have the following:
    • create one ArrayList of City objects and initialize the ArrayList with City objects using the loadValues() method of the City.java class
    • call printData() passing the City ArrayList as argument
    • call findMax() passing the City ArrayList and printing all cities with the worst air quality
    • call findMin() passing the City ArrayList and printing all cities with the best air quality
    • Your main() method may need some local variables and loops to accomplish the above tasks
  • printData() This method has a parameter for the City ArrayList and should print the name of the city and the pmValue (the toString() method of the City class already does this)
  • findMax() This method has a parameter for the City ArrayList and should find and return the maximum value of all the pollution values.
  • findMin() This method has a parameter for the City ArrayList and should find and return the minimum value of all the pollution values.

image text in transcribedimage text in transcribedimage text in transcribed

Data Sample A City PM2.5 Level 58 Colombo 48 Bandaranaike International Airport Dambullagama Dehiwala-Mount Lavinia 52 56 Galle 49 Gampaha District Station 62 Horana 61 Jaffna 47 Kalmunai 51 66 Kandy Kankasanturai 44 56 Katunayake Kolonnawa 57 58 Nawalapitiya Station Norochcholai 55 Ratmalana Airport 54 Ratnapura New Town 56 import java.util.ArrayList;|| class Main { 1/ make sure to pass the correct arguments when calling the methods public static void main(String[] args) { //instantiate 1 ArrayList of City objects and initialize the ArrayList with City objects using the loadValues() method in the City class //call the printData to print all the cities and their PM2.5 level //call the findMax method and print all the cities (using a loop) with the worst air quality //call the findin method and print all the cities (using a loop) with the best air quality } //end of main method // The method below should print all of the cities and their PM2.5 level public static void printData(ArrayList c) { } // The method below should find the maximum pollution value in the ArrayList of City objects instantiated above // The method will need to call the getPMValue method in the City class to retrieve each city's pollution value and return the maxinum pollution value public static int findMax(ArrayList c) { return -1; } // The method below should find the minimum pollution value in the ArrayList of City objects instantiated above // The method will need to call the getPMValue method in the City class to retrieve each city's pollution value and return the minimum pollution value public static int findMin(ArrayList c) { return -1; } } import java.util.ArrayList; // instance variables are the city name and the PM value for that city class City { String name; int pmValue; public City() { name = "no name"; pmValue = 0; } public City(String nm, int pm) { name = nm; pmValue = pm; } public String getName() { return name; } public int getPMValue() { return pmValue; public static ArrayList loadValues() { // set up parallel arrays with the city names and pollution data // initialize each array with the information from Student Data Set A String[] cities = {"Bandaranaike International Airport", "Dambullagama", "Dehiwala-Mount Lavinia", "Galle", "Gampaha District Station", "Horana", "Jaffna", "Kalmunai", "Kandy", "Kankasanturai", "Katunayake", "Kolonnawa", "Nawalapitiya Station", "Norochcholai", "Ratmalana Airport","Ratnapura New Town"}; int[] pmValues = {58,48,52,56,49,62,61,47,51,66,44,56,57,58,55,54,56}; //create an array of City objects ArrayList theC = new ArrayList(); for (int i = 0; i

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago