Question

The purpose of this assignment is to prove that you can build and use an arraylist...

The purpose of this assignment is to prove that you can build and use an arraylist (which is different than an array).

Your program will ask the user to start entering names and to type "Quit" to quit. Each of these names will be stored in an arraylist. (You can assume that no one will be named "Quit".) After they have entered all of the names and typed "Quit" they should receive a list of everything they entered. The program should operate as follows:

You must use a While loop and an arraylist for this program. Assignments submitted without a While loop and an arraylist will not be graded.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***************************Program11.java*********************/

import java.util.ArrayList;
import java.util.Scanner;

public class Program11 {

   public static void main(String[] args) {

       ArrayList<String> names = new ArrayList<String>();

       String name = "";
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter names: ");
       while (!name.equalsIgnoreCase("quit")) {

           name = scan.next();
           if (name.equalsIgnoreCase("quit")) {

               break;
           }
           names.add(name);

       }

       System.out.println("Names are: "+names);
       scan.close();
   }
}

/***********************output********************/

Enter names:
Virat John Ajay
JKS
MS
Dolly Quit
Names are: [Virat, John, Ajay, JKS, MS, Dolly]

e Console X Search Ju JUnit <terminated > Program11 [Java Application] C:\Program Files\Java\jre1.8.0 Enter names: Virat John

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
The purpose of this assignment is to prove that you can build and use an arraylist...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

  • Array Class Assignment

    This is a two-part assignment. It is better to submit the files for both parts when you are done than to submit part 1 first and part 2 later.In the Array.h file includes the class definition and member functions implementations.PART 1Write And Test An Array Class [Array.TestDriver.cpp] Write a data structures class. The resulting class can be used in any program in place of a C++ array, in case you want the advantages of range safety and built-in size tracking.Requirements....

  • Use C++ to implement a program that can store and output 5 integers, where the user...

    Use C++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. (5 points) 2. Output the content (value) that stored in the array of five elements. (10 points) 3. Continue to ask the user to store for storing data into another array. (10 points)

  • Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This...

    Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This will be the 3x3 matrix. Then, input 3, 64-bit, floating-point values. This will be a single-dimensional array and is the vector. Your program will simply ask the user to enter matrix values. Remember, there are 9 of these, but they need to be stored into a 3x3 multi-dimensional array (row-major). Then, your program will ask for the vector values, which will be stored into...

  • Use DevC++ to implement a program that can store and output 5 integers, where the user...

    Use DevC++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. (5 points) 2. Output the content (value) that stored in the array of five elements. (10 points) 3. Continue to ask the user to store for storing data into another array(store and output 5 integers). (10 points) Prelude to Programming...

  • Using Java Create an application that creates and displays a list of names using an array....

    Using Java Create an application that creates and displays a list of names using an array. Then modify the application to create and use a list of numbers. Console for the names application Please enter a name or type “exit” to quit: Diane Please enter a name or type “exit” to quit: Joe Please enter a name or type “exit” to quit: Greta Please enter a name or type “exit” to quit: Henry Please enter a name or type “exit”...

  • Write a new program called TrickOr Treat that will do the following 1. In a while...

    Write a new program called TrickOr Treat that will do the following 1. In a while loop, say "Trick or Treat!" and allow the user to type in the name of a candy and store it in an ArrayList. Once the user types "Trick", then the loop should stop. Then, print out the total number of candies on the screen. (See example below) [1 points] 2. Write a method called countSnickers that will take an ArrayList of candy as an...

  • Create a Java program which asks the user how many names they want to enter. The...

    Create a Java program which asks the user how many names they want to enter. The program should then instantiate an array that will hold this many names. The main method should call a method, getNames() to allow the user to enter the names. A for loop should be used in this method. Once the names are entered, the main method should call another method displayNames() which will use a while loop to display the names entered.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT