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 5.
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 main(String[] args){
Scanner inputScanner = new Scanner(System.in);
CityList.inputScanner = inputScanner; // Set the input scanner for the CityList class
int listSize =5; // Set the size of the list
// Create a CityList object and populate the list
String[] cityNames = CityList.createCityList();
CityList.populateList(cityNames);
// Print the original array of city names
System.out.println("Original Array:");
for (String city : cityNames){
System.out.println(city);
}
// Find and print the minimum length of city names
int minLength = CityList.findMinimumLength(cityNames);
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 main(String[] args){
Scanner inputScanner = new Scanner(System.in);
CityList.inputScanner = inputScanner; // Set the input scanner for the CityList class
int listSize =5; // Set the size of the list
// Create a CityList object and populate the list
String[] cityNames = CityList.createCityList();
CityList.populateList(cityNames);
// Print the original array of city names
System.out.println("Original Array:");
for (String city : cityNames){
System.out.println(city);
}
// Find and print the minimum length of city names
int minLength = CityList.findMinimumLength(cityNames);
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 populateList(String[] cityNames){}
public static int findMinimumLength(String[] 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 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 Accounting Questions!