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 and both inclusive.
Ex: If the input is:
Hanna Barge Gillette Adomstown
then the output is:
City: Hanna, Population:
City: Adomstown, Population:
import java.util.Scanner;
import java.util.ArrayList;
public class SmallTowns
private ArrayList cityList new ArrayList;
public void inputCitiesScanner scnr
City currCity;
String currName;
int currPopulation;
int cityCount;
int i;
cityCount scnrnextInt;
for i ; i cityCount; i
currName scnrnext;
currPopulation scnrnextInt;
currCity new City;
currCity.setNameAndPopulationcurrName currPopulation;
cityList.addcurrCity;
Your code goes here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
