
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
Concept explainers
Question
New JAVA code can only be added between lines 9 and 10, as seen in image.
![**Instructions:**
Declare and initialize a reference variable for an `ArrayList` named `animalsList` that stores items of type `String`. Read integer `numAnimals` from input. Then, insert `numAnimals` "sheep" at the end of `animalsList`.
**Example:**
If the input is 3, then the output is:
```
sheep sheep sheep
```
**Code Explanation:**
```java
import java.util.Scanner;
import java.util.ArrayList;
public class MakeAnimalsList {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numAnimals;
int i;
/* Variable declarations go here */
/* Your code goes here */
// Traversing a List using indexes
for (i = 0; i < animalsList.size(); ++i) {
System.out.print(animalsList.get(i) + " ");
}
System.out.println();
}
}
```
**Key Components:**
1. **Imports:**
- `java.util.Scanner`: Used for obtaining input from the user.
- `java.util.ArrayList`: Provides the `ArrayList` class to create dynamic arrays.
2. **Main Class and Method:**
- `MakeAnimalsList`: Class containing the main method.
- `main(String[] args)`: The entry point for the program.
3. **Variables:**
- `Scanner scnr`: For reading user input.
- `int numAnimals`: Stores the number of animals.
- `int i`: Loop counter.
4. **Comments:**
- Placeholder comments indicate where the variable declarations and core logic should be placed.
5. **Loop:**
- A `for` loop is used to traverse and print each element in `animalsList`.
This code snippet provides the structure, but the logic to read `numAnimals` and update `animalsList` is left for implementation. Fill in the necessary code under the indicated comment sections to complete the task.](https://content.bartleby.com/qna-images/question/0cc153ae-b205-4fb2-9991-7cf6a21d5016/d8551e13-46ec-4da2-b62c-f85a5c8856e3/9701q27_thumbnail.png)
Transcribed Image Text:**Instructions:**
Declare and initialize a reference variable for an `ArrayList` named `animalsList` that stores items of type `String`. Read integer `numAnimals` from input. Then, insert `numAnimals` "sheep" at the end of `animalsList`.
**Example:**
If the input is 3, then the output is:
```
sheep sheep sheep
```
**Code Explanation:**
```java
import java.util.Scanner;
import java.util.ArrayList;
public class MakeAnimalsList {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numAnimals;
int i;
/* Variable declarations go here */
/* Your code goes here */
// Traversing a List using indexes
for (i = 0; i < animalsList.size(); ++i) {
System.out.print(animalsList.get(i) + " ");
}
System.out.println();
}
}
```
**Key Components:**
1. **Imports:**
- `java.util.Scanner`: Used for obtaining input from the user.
- `java.util.ArrayList`: Provides the `ArrayList` class to create dynamic arrays.
2. **Main Class and Method:**
- `MakeAnimalsList`: Class containing the main method.
- `main(String[] args)`: The entry point for the program.
3. **Variables:**
- `Scanner scnr`: For reading user input.
- `int numAnimals`: Stores the number of animals.
- `int i`: Loop counter.
4. **Comments:**
- Placeholder comments indicate where the variable declarations and core logic should be placed.
5. **Loop:**
- A `for` loop is used to traverse and print each element in `animalsList`.
This code snippet provides the structure, but the logic to read `numAnimals` and update `animalsList` is left for implementation. Fill in the necessary code under the indicated comment sections to complete the task.
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 4 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
- Using Java. Implement a deque, except base your implementation on an array. The constructor for the class should accept an integer parameter for the capacity of the deque and create an array of that size. Use a graphical user interface based on an array of text fields similar to what is shown in the image attached. Test your deque class by constructing a deque with capacity 10. Below also is an unfinished code for the challenge. #################################Array Based Deque################################# public class ArrayBaseDeque{private String [ ] q; // Holds queue elementsprivate int front; // Next item to be removedprivate int rear; // Next slot to fillprivate int size; // Number of items in queue private int count = 0;/**Constructor.@param capacity The capacity of the queue.*/ArrayBaseDeque(int capacity){q = new String[capacity];front = 0; rear = 0;size = 0;}/**The capacity method returns the length of the array used to implement the queue.@return The capacity of the…arrow_forwardPlease solve this in java, using the Gui system(Jframe, Jpanel, etc) from java, not java fx thanks.arrow_forwardIn Java import java.util.Scanner;public class Image {int numberOfPhotos; // photos on rolldouble fStop; // light let it 1.4,2.0,2.8 ... 16.0int iso; // sensativity to light 100,200, 600int filterNumber; // 1-6String subjectMatter;String color; // black and white or colorString location;boolean isblurry;public String looksBlurry(boolean key){if ( key == true){return "Photo is Blurry";}else{return "Photo is Clear";}}public void printPhotoDetails (String s1){Scanner br= new Scanner(System.in);String subjectMatter=s1;System.out.println("Data of Nature photos:");System.out.println("Enter number of photos:");numberOfPhotos= br.nextInt();int i=1;while(true){System.out.println("Enter Filter number of photos"+i+":");filterNumber= br.nextInt();System.out.println("Enter colour of photo"+i+ ":");String color= br.next();System.out.println("Enter focal length of photo"+i+":");fStop= br.nextInt();System.out.println("Enter location of photo"+i+":");String location= br.next();System.out.println("Enter…arrow_forward
- JAVA SWINGI have definied a straight TUBE as: int rectWidth = 25; // replace 50 with the desired width of the rectangleint rectHeight = 200; // replace 200 with the desired height of the rectangleint rectX = (this.getWidth() - rectWidth) / 2;int rectY = (this.getHeight() - rectHeight) / 2;game.fillRect(rectX, rectY, rectWidth, rectHeight);I need L tube, which connects the straight tubes. How to define L tubes?arrow_forwardIn Java, design a class that models a 6-sided die. The die will be used in a game. Simulate a roll of the die, return a random value from {1,2,3,4,5,6}.arrow_forwardJava programarrow_forward
- Java. Please use the template in the picture.arrow_forwardImplement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forwardWrite a Java program with a single-dimension array that holds 10 integer numbers and identify the maximum value of the 10 numbers. Next sort the array using a bubble sort and display the array before and after sorting.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