Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started