Question

1. use the main method 2. ask the user to enter a name at the terminal...

1. use the main method
2. ask the user to enter a name at the terminal
3. ask the user to continue to add name (use Y/N)
4. as long as the user type Y. keep asking them to enter a name.
5. at N (no) print out the following:
LAST NAME, firstname

Language: java

for all lthe entries.



ex.

Enter a Name

Tom Harper

Enter a new name ? (Y/N)

Y

Enter a Name

Sue Bird

Enter a new name ? (Y/N)

Y

Enter a Name

Rich Mark

Enter a new name ? (Y/N)

N

HARPER, Tom

BIRD, Sue

MARK, Rich

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

public class StoreNames {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<String> names = new ArrayList<>();
        String choice;
        do {
            System.out.println("Enter a Name");
            names.add(in.nextLine());
            System.out.println("Enter a new name ? (Y/N)");
            choice = in.nextLine();
        } while (choice.equals("Y"));
        for (int i = 0; i < names.size(); i++) {
            String[] words = names.get(i).split(" ");
            System.out.println(words[1].toUpperCase() + ", " + words[0]);
        }
    }

}
Add a comment
Know the answer?
Add Answer to:
1. use the main method 2. ask the user to enter a name at the terminal...
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
  • (2) Write a loop wherein you ask the user if they want to enter another complete...

    (2) Write a loop wherein you ask the user if they want to enter another complete name (lastname , firstname) and account balance. Have the user respond with a single character 'y' or 'n' (note: the user will have to hit the key after the single character ‘y’ or ‘n’) c is the language used

  • Using C# Create a “Main” method that will take user input one line at a time...

    Using C# Create a “Main” method that will take user input one line at a time until they enter the phrase “done”. Store each line entered into an ArrayList, so that one element of the ArrayList is one line of user input. You do NOT need to write your own ArrayList class, please use the standard library implementation of an ArrayList. After the user finishes typing in input, ask the user for a location and file name. Save the contents...

  • Ask the user to enter a message Ask the user how many time they want to...

    Ask the user to enter a message Ask the user how many time they want to print the message Then use "while","do-while" and "for" loop to print the message. Show the number at the beginning of the lines when printing. For example: Enter your message: Welcome to Java How many time you want to print this message: 3 Using "while" loop: 1=> Welcome to Java 2=> Welcome to Java 3=> Welcome to Java Using "do-while" loop: 1=> Welcome to Java...

  • JAVA Ask the user for integers. If the user did not enter an integer, ask again....

    JAVA Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Do not use try-catch. EXAMPLE OUTPUT: Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2]...

  • Use the pseudocode below to create your program: Ask the user to Enter their marks. In...

    Use the pseudocode below to create your program: Ask the user to Enter their marks. In the while loop condition, IF the score entered is >=60, then print “Congratulations! Passed” After printing “Congratulations! Passed””, ask the user to enter the mark again. When the above while condition is not met then print “Sorry! Fail”

  • We use JAVA. Thanks.    Create an application whose main method asks the user to enter...

    We use JAVA. Thanks.    Create an application whose main method asks the user to enter an n by m integer matrix that contains nm integer numbers. n and m should be between 1 and 10. If the user enters a             number less than 1 or greater than 10, the program will continue to ask the user to enter an integer number between 1 and 10. The program should print the sum of the boundary elements of the matrix....

  • Using java program, create a Username class. ask user to type username 1)username length have to...

    Using java program, create a Username class. ask user to type username 1)username length have to >1 and <15 2)username can not include any special character (ex.!@##$}{|\....) ,but it also have to type Spanish or other foreign language 3)user can not include any empty space (ex. user name) all of three error have to print out. and if there is any error contains, have to ask user to input user name again. for example: input username: #$%he f username can't...

  • Display a welcome message and then ask the user to enter his/her name Display a personal...

    Display a welcome message and then ask the user to enter his/her name Display a personal welcome message by addressing the user by his/her name. Declare a constant and assign a number to it as the Conference Room capacity. Ask the user how many people are attending the meeting. Display a meaningful message for each of the three different scenarios. The message informs the user whether he/she can have the requested room and also displays the number of people that...

  • Write Java code that does the following Ask the user to enter a file name. Ask...

    Write Java code that does the following Ask the user to enter a file name. Ask the user for two integers as the lower bound and the upper bound. Use a loop to write all the odd numbers between the lower bound and the upper bound (inclusive) to the file, and then close the file. Use either while loop, do while loop, or for loop to complete the program. PrintWriter class is used. The file is closed before the program...

  • (Java) HELP! Create a program that will ask the user to enter their first name and...

    (Java) HELP! Create a program that will ask the user to enter their first name and their favorite number. Ask the user if they would like the information repeated back to them. If they type "Y" display the answers back to them. If they type anything else, display the word "Goodbye". An example of what your output window should look like is below. The system-generated output is in red. The user-provided input is in green. (Your actual program will only...

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