Write an app that has a class named City which has attribute
Write an app. that has a class named City, which has attributes name, state, yearOfFounding, and population. Provide at least 2 different constructor methods, plus getters and setters for each attribute. Create a 2nd class named CityDemo that allows the user to create and edit some City instances, so we need a loop that asks: \"Would you like to create another City instance (y/n)?\" The CityDemo logic that asks the user to enter year must contain an input validation loop. Same idea for population. See the Bank Account + AccountTest classes described in textbook pages 374-80 as a rough guide to some of what you\'ll need. In NetBeans, start by creating a new Project named CityDemo (check the box to \"Create Main Class\"), then select Pile, New Pile, leave the defaults as Java ... Java Class (click Next), then type in City where it prompts for Class Name, and click Finish. Now you can type in your code for these 2 classes. Provide hardcopy in class and email copy of your app as 2 .javafiles
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
---------------------------------------------------------------
OUTPUT:
Enter city name:
City 1
Enter city state:
xyz
Enter year of founding:
1990
Enter population:
391231
Would you like to create another city instance(y/n)?
y
Enter city name:
City 2
Enter city state:
abc
Enter year of founding:
2n
Invalid year! please try again..
2001
Enter population:
22231w
Invalid population! please try again..
238129
Would you like to create another city instance(y/n)?
n
City{name=\'City 1\', state=\'xyz\', yearOfFounding=1990, population=391231}
City{name=\'City 2\', state=\'abc\', yearOfFounding=2001, population=238129}
