
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
I had this solution but kept getting error that it couldn't find symbol on the .set part.
currPopulation = scnr.nextInt();
while (currPopulation >=0) {
currTown = new Town();
currName = scnr.next();
currTown.setNameAndPopulation(currName, currPopulation);
townList.add(currTown);
currPopulation = scnr.nextInt();
}
System.out.println("To end: 'done'");
![Use scnr to read each pair of inputs, string currName and integer currPopulation, until "done" is read from input. Create each
Town object with currName and currPopulation as arguments and append each object to ArrayList townList.
Ex: If the input is Goshen 3200 Jackson 3300 Asaph 2600 Natrona 2800 done, then the output is:
Town: Goshen, Population: 3200
Town: Jackson, Population: 3300
Town: Asaph, Population: 2600
Town: Natrona, Population: 2800
2 import java.util.ArrayList;
3
4 public class Towns {
5 public static void main(String[] args) {
6
7
8
9
10
11 12 13 14 15 16 17 18 10
Scanner scnr = new Scanner(System.in);
ArrayList<Town> townList = new ArrayList<Town>();
Town currTown;
String currName;
int currPopulation;
int i;
Towns.java Town.java
/* Your solution goes here *1
for (i = 0; i < townList.size(); ++i) {
currTown = townList.get(i);
currTown.print ();
}](https://content.bartleby.com/qna-images/question/86e13c63-39cf-407f-bae2-01e57c0678e7/ce9fabe8-e610-4639-82e2-37078de2e7fc/3r1wxob_thumbnail.jpeg)
Transcribed Image Text:Use scnr to read each pair of inputs, string currName and integer currPopulation, until "done" is read from input. Create each
Town object with currName and currPopulation as arguments and append each object to ArrayList townList.
Ex: If the input is Goshen 3200 Jackson 3300 Asaph 2600 Natrona 2800 done, then the output is:
Town: Goshen, Population: 3200
Town: Jackson, Population: 3300
Town: Asaph, Population: 2600
Town: Natrona, Population: 2800
2 import java.util.ArrayList;
3
4 public class Towns {
5 public static void main(String[] args) {
6
7
8
9
10
11 12 13 14 15 16 17 18 10
Scanner scnr = new Scanner(System.in);
ArrayList<Town> townList = new ArrayList<Town>();
Town currTown;
String currName;
int currPopulation;
int i;
Towns.java Town.java
/* Your solution goes here *1
for (i = 0; i < townList.size(); ++i) {
currTown = townList.get(i);
currTown.print ();
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- The play method in the Player class of the craps game plays an entire game without interaction with the user. Revise the Player class so that its user can make individual rolls of the dice and view the results after each roll. The Player class no longer accumulates a list of rolls, but saves the string representation of each roll after it is made. Add new methods rollDice, getNumberOfRolls, isWinner, and isLoser to the Player class. The last three methods allow the user to obtain the number of rolls and to determine whether there is a winner or a loser. The last two methods are associated with new Boolean instance variables (winner and loser respectively). Two other instance variables track the number of rolls and the string representation of the most recent roll (rollsCount and roll). Another instance variable (atStartup) tracks whether or not the first roll has occurred. At instantiation, the roll, rollsCount, atStartup, winner, and loser variables are set to their appropriate…arrow_forwardI don't get the "//To be implemented" comments, what am I supposed to do?Also, are the header files and header files implementation different? Like is the linkedList.h different than the linkedList.h (implementation)?arrow_forwardI'm trying to understand LargeIntList classes for lists, I was wondering these statements or True or False? either or, can you please explain your answers? If you need more info, I can provide an image of the textbook I am refering LargeIntList to, it is chapter 6, section 6. Thank you. Supports addition of elements at the front of the list, the end of the list, and anywhere in between. Can hold objects of any Java class. Has only O(1) operations, including its constructor. Provides more than one Iterator.arrow_forward
- ---for example, Data abstraction is a powerful concept in computer science that allows programmers to treat code as objects car objects, chair objects, people objects, etc. That way, programmers don't have to worry about how code is implemented they just have to know what it does. Data abstraction mimics how we think about the world. For example, when you want to drive a car, you don't need to know how the engine was built or what kind of material the tires are made of. You just have to know how to turn the wheel and press the gas pedal. An abstract data type consists of two types of functions: • Constructors: functions that build the abstract data type. • Selectors: functions that retrieve information from the data type. For example, say we have an abstract data type called city. This city object will hold the city's name, and its latitude and longitude. To create a city object, you'd use a constructor like city=make_city (name, lat, lon) To extract the information of a city object,…arrow_forwardLanguage Pythonarrow_forwardSuppose you have created a new class: SortedLinkedList. This class is derived from LinkedList (single links). You are asked to overload the method Insert. The method Insert will no longer take in a parameter position, this is because now Insert will place the element in the correct position such that the list is always sorted. Write the C++ code for the implementation of that Insert method.arrow_forward
- can you give me the code to the following questionarrow_forwardHello!I'm currently in the process of developing an algorithm for a reverse method for a singly-linked list--not an array, which is a much easier algorithm and I have done before. I'm writing in Java. I'm working from a pre-written SinglyLinkedList class with certain methods (intentionally) empty, for us to fill.I have, unbelievably, spent somewhere around 5 hours going through drafts. The easiest implementation I've conceived of would be to create a second list with which to import the nodes and elements starting from the tail. public void reverse() {<Integer> list2 = new SinglyLinkedList();for (size) { list2.addLast(tail); list1.remove(tail); }}This is the rough draft pseudocode for the aforementioned implementation.If we were to work within the same list, instead of creating a new one we would have to go through, for a size of 10, a hundred iterations. Obviously, there are a number of problems.First, reverse() has been defined as a void method. It's not supposed to return…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education