Question: You are tasked with implementing a program that manages a list of city names. Follow the instructions below to create the program: CityList Class Declare
You are tasked with implementing a program that manages a list of city names. Follow the instructions below to create the program:
CityList Class
Declare a public static Scanner object named inputScanner to read input from the keyboard.
Declare a public static int variable named listSize to store the size of the list.
Main Method GIVEN
A Scanner object inputScanner to reads input from the keyboard.
Sets listSize to
Declares a String Array reference named cityNames with a size of listSize.
Call the method createCityList with no parameters, which returns a reference to a String Array, and assign it to cityNames.
Call the method populateList with the String Array cityNames to read in listSize city names using inputScanner.nextLine
Print out the original String Array cityNames using an enhanced for loop.
Call the method findMinimumLength with the String Array cityNames and store the returned value in a variable.
createCityList Method
Implement a method createCityList with no parameters that creates and returns a reference to a String Array.
populateList Method
Implement a method populateList that takes a String Array parameter list and reads in listSize number of city names using inputScanner.nextLine to populate the array. Return the populated array.
findMinimumLength Method
Implement a method findMinimumLength that takes a String Array parameter names and returns the minimum length of strings in the array as an integer.
Driver
import java.util.Scanner;
public class Driver
public static void mainString args
Scanner inputScanner new ScannerSystemin;
CityList.inputScanner inputScanner; Set the input scanner for the CityList class
int listSize ; Set the size of the list
Create a CityList object and populate the list
String cityNames CityList.createCityList;
CityList.populateListcityNames;
Print the original array of city names
System.out.printlnOriginal Array:";
for String city : cityNames
System.out.printlncity;
Find and print the minimum length of city names
int minLength CityList.findMinimumLengthcityNames;
System.out.println
Minimum Length of City Names: minLength;
inputScanner.close; Close the scanner
Driver
import java.util.Scanner;
public class Driver
public static void mainString args
Scanner inputScanner new ScannerSystemin;
CityList.inputScanner inputScanner; Set the input scanner for the CityList class
int listSize ; Set the size of the list
Create a CityList object and populate the list
String cityNames CityList.createCityList;
CityList.populateListcityNames;
Print the original array of city names
System.out.printlnOriginal Array:";
for String city : cityNames
System.out.printlncity;
Find and print the minimum length of city names
int minLength CityList.findMinimumLengthcityNames;
System.out.println
Minimum Length of City Names: minLength;
inputScanner.close; Close the scanner
CityList
import java.util.Scanner;
public class CityList
public static String createCityList
public static void populateListString cityNames
public static int findMinimumLengthString names
Input
New York
Los Angeles
Chicago
San Francisco
Seattle
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
