Question: JAVA - The program first reads integer cityCount from input, representing the number of pairs of inputs to be read. Each pair has a string

JAVA
-
The program first reads integer cityCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an integer, representing the city's name and population, respectively. One City object is created for each pair and added to ArrayList cityList. Write the printCitiesInRange() method in the SmallTowns class using print() to output all the City objects with population between 1500 and 2800, both inclusive.
Ex: If the input is:
4
Hanna 1500 Barge 3900 Gillette 4100 Adomstown 2800
then the output is:
City: Hanna, Population: 1500
City: Adomstown, Population: 2800
import java.util.Scanner;
import java.util.ArrayList;
public class SmallTowns {
private ArrayList cityList = new ArrayList();
public void inputCities(Scanner scnr){
City currCity;
String currName;
int currPopulation;
int cityCount;
int i;
cityCount = scnr.nextInt();
for (i =0; i < cityCount; ++i){
currName = scnr.next();
currPopulation = scnr.nextInt();
currCity = new City();
currCity.setNameAndPopulation(currName, currPopulation);
cityList.add(currCity);
}
}
/* Your code goes here */
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!