Question: Not sure what it needs me to change Write the inputCities ( ) method in the SmallTowns class. Within inputCities ( ) , use scnr

Not sure what it needs me to change
Write the inputCities() method in the SmallTowns class. Within inputCities(), use scnr to read pairs of inputs, integer currPopulation and string currName, until -99 is read from input. Create each City object with currPopulation and currName as arguments and append each object to ArrayList cityList.
Ex: If the input is 3600 Opal 2600 Yonder 2200 Goshen 4500 Worland -99, then the output is:
City population: 3600, Name: Opal City population: 2600, Name: Yonder City population: 2200, Name: Goshen City population: 4500, Name: Worland
Ex: If the input is 3600 Opal 2600 Yonder 2200 Goshen 4500 Worland -99, then the output is:
City population: 3600, Name: Opal
City population: 2600, Name: Yonder
City population: 2200, Name: Goshen
City population: 4500, Name: Worland
import java.util.Scanner;
import java.util.ArrayList;
public class SmallTowns {
private ArrayList cityList = new ArrayList();
CitySystem city;
public void inputCities(){
Scanner scnr = new Scanner(System.in);
int currPopulation = scnr.nextInt();
if (currPopulation ==-99){
}
String currName = scnr.next();
City city = new City();
city.setDetails(currPopulation, currName);
cityList.add(city);
Failed to compile
CitySystem.java:9: error: method inputCities in class SmallTowns cannot be applied to given
smallTowns.inputCities(scnr);
required: no arguments
found: Scanner
reason: actual and formal argument lists differ in length
1 error
public void printCities(){
City currCity;
int i;
for (i =0; i cityList.size(); ++i){
currCity = cityList.get(i);
currCity.print();
}
}
}
Failed to compile
CitySystem.java:9: error: method inputcities in class SmallTowns cannot be applied to given 1
smallTowns.inputCities(scnr);
required: no arguments
found: Scanner
reason: actual and formal argument lists differ in length
1 error
public class City {
private int population;
private String name;
public void setDetails(int newPopulation, String newName){
population = newPopulation;
name = newName;
}
public void print(){
System.out.println("City population: "+ population +", Name: "+ name);
}
}
import java.util.Scanner;
import java.util.ArrayList;
public class CitySystem {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
SmallTowns smallTowns = new SmallTowns();
smallTowns.inputCities(scnr);
smallTowns.printCities();
}
}
Not sure what it needs me to change Write the

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 Programming Questions!