Question

Create a Java program application that creates an ArrayList that holds String objects. It needs to...

Create a Java program application that creates an ArrayList that holds String objects. It needs to prompt the user to enter the names of friends, which are then put into the ArrayList; allow the user to keep adding names until they enter "q" to quit.

After input is complete, display a numbered list of all friends in the list and prompt the user to enter the number of the friend they wish to delete. After deleting that entry, output the new list of friends.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.ArrayList;
import java.util.Scanner;

public class FriendList {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<String> friends = new ArrayList<>();
        String name;
        while (true) {
            System.out.print("Enter your friend's name(q to exit): ");
            name = in.nextLine();
            if(name.equals("q")) {
                break;
            }
            friends.add(name);
        }
        System.out.println("\nFriends");
        for(int i = 0; i < friends.size(); i++) {
            System.out.println(i + ": " + friends.get(i));
        }
        System.out.print("\nEnter friend number to delete: ");
        int number = in.nextInt();
        friends.remove(number);
        System.out.println("\nFriends");
        for(int i = 0; i < friends.size(); i++) {
            System.out.println(i + ": " + friends.get(i));
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Create a Java program application that creates an ArrayList that holds String objects. It needs to...
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
  • 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”...

  • need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user...

    need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user objects. The Facebook class should have methods to list all of the users (i.e. print out their usernames), add a user,delete a user, and get the password hint for a user You will also need to create a driver program. The driver should create an instance of the Facebook class and display a menu containing five options: list users...

  • Create a java program that reads an input file named Friends.txt containing a list 4 names...

    Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do:   1. Add a new name   2. Change a name 3. Delete a name 4. Print the list   or 5. Quit    When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...

  • Java ArrayList Sorting Alphabetically

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or byentering the string “quit”.2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For example, if...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Question 2: Your task is to create a GUI application that allows a user to create a group of Hero objects s (think Lord of the Your group may be a small band of two or three Heroes or it may cons...

    Question 2: Your task is to create a GUI application that allows a user to create a group of Hero objects s (think Lord of the Your group may be a small band of two or three Heroes or it may consist of Rines or the Marvel Cinenatic Universe here) You have been given the compiled version of the dlass encapsulating a Hero and you have also been given the specification. Your job is to create a GUI application that...

  • Write a Java program that does the following: 1. Creates a string array called firstNames that...

    Write a Java program that does the following: 1. Creates a string array called firstNames that holds these values "John", "Frank", "Nick", "Amanda", "Brittany", "Amy", "Deborah", and "Stirling". 2. Creates another string array called lastNames that holds these values "Thompson", "Smith", "Jones", "Keribarian", "Lu", "Banafsheh", "Spielberg", "Jordan", "Castle" and "Simpson". 3. Now add a method that creates an array list called randomNames which picks a random first name from the array in step 1 and a random last name in...

  • Java Email Template Application: Create an application that creates a series of emails as outlined below....

    Java Email Template Application: Create an application that creates a series of emails as outlined below. Create an array of email addresses that include the following data: "   james   ,butler,[email protected]" "Josephine,Darakjy,[email protected]" "ART,VENERE,[email protected]" Store a template for a mass email like this: String template =     "To:      {email}\n" +     "From:    [email protected]\n" +     "Subject: Deals!\n\n" +     "Hi {first_name},\n\n" +     "We've got some great deals for you. Check our website!"; When the application starts, it should read the email...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

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