Answered step by step
Verified Expert Solution
Link Copied!

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 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

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What other bills do I have to pay?

Answered: 1 week ago