Question

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” to quit: exit

The names you entered were:

Diane

Joe

Greta

Henry

Console for the numbers application

Please enter a number or type “exit” to quit: 12.5

Please enter a number or type “exit” to quit: 75

Please enter a number or type “exit” to quit: 200

Please enter a number or type “exit” to quit: -.02

Please enter a number or type “exit” to quit: exit

The numbers you entered were:

12.5

75

200

-.02

Sum: 287.48

Average: 71.87

Chapters 7-13 Review Exercise 2: Names and Numbers (continued)

Specifications

Part 1:

  • Prompt the user to enter a first name, or enter “exit” to quit.
  • Notice there will be only one prompt in this program, instead of one to get the name and the other to ask if the user wants to continue.
  • Store all names in an array. When the user enters “exit” display all the names entered.

Part 2:

  • Make a copy of the program you have just written, and modify it as follows.
  • Prompt the user to enter a number, or enter “exit” to quit.
  • The numbers entered may be decimal numbers or integers.
  • Store all numbers in an array.
  • When the user enters “exit”, display the numbers entered, their sum, and the average.
  • For this version of the program, you must read everything as a string, and then convert the numbers appropriately before performing the calculations.
0 0
Add a comment Improve this question Transcribed image text
Answer #1


import java.util.Scanner;

public class Names {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String arr[]=new String[100];
       int size=0;
       String s;
       while(true) {
           System.out.println("Please enter a name or type 'exit' to quit: ");
           s=sc.nextLine();
           if(s.equalsIgnoreCase("exit"))
               break;
           arr[size++]=s;
          
       }
       System.out.println("The names you entered were:");
       for(int i=0;i<size;i++)
           System.out.println(arr[i]);
   }
}

import java.util.Scanner;

public class Numbers {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       double arr[]=new double[100];
       int size=0;
       String s;
       double sum=0;
       while(true) {
           System.out.println("Please enter a name or type 'exit' to quit: ");
           s=sc.nextLine();
           if(s.equalsIgnoreCase("exit"))
               break;
           arr[size]=Double.parseDouble(s);
           sum+=arr[size++];
       }
       System.out.println("The names you entered were:");
       for(int i=0;i<size;i++)
           System.out.println(arr[i]);
       System.out.println("Sum: "+sum);
       System.out.println("Average: "+(sum/size));
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Using Java Create an application that creates and displays a list of names using an array....
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
  • 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...

  • 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...

  • Using arrays create a personal phone directory that contains room for first names and phone numbers...

    Using arrays create a personal phone directory that contains room for first names and phone numbers for 20 people. Using the "names.txt" retrieve the first name and phone number for each person and store in arrays (parallel). Prompt the user for a name, search for the name, and if name is found in the array, display the corresponding phone number. If the name is not found, prompt the user to enter a phone number, and add the new name and...

  • Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

    Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • 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...

  • in java Complete Program that simulates a login procedure. The program reads a list of names,...

    in java Complete Program that simulates a login procedure. The program reads a list of names, email addresses and passwords from a file p3.txt. Store the information in parallel array lists names, emails and passwords. Your program will prompt the user for their email address. If the email is not in the system, prompt the user to try again. Provide the option to quit. If the email is found in the system, prompt the user to enter their password. After...

  • Write a program that has an array of at most 50 strings that hold people’s names...

    Write a program that has an array of at most 50 strings that hold people’s names and phone numbers. You can assume each string’s length is no more than 40. You may make up your own strings, or use the following: "Becky Warren, 555-1223" "Joe Looney, 555-0097" "Geri Palmer, 555-8787" "Lynn Presnell, 555-1212" "Holly Gaddis, 555-8878" "Sam Wiggins, 555-0998" "Bob Kain, 555-8712" "Tim Haynes, 555-7676" "Warren Gaddis, 555-9037" "Jean James, 555-4939" "Ron Palmer, 555-2783" The program should ask the user...

  • Write a console application in c# that uses a one dimensional array; prompt the user to...

    Write a console application in c# that uses a one dimensional array; prompt the user to enter letters, ( a, b, c, … z). As each letter is input, store it in the array only if it is not a duplicate of previous letters entered. After 7 unique letters have been entered, display the unique values in the array. Be sure to test with duplicate values.

  • Create a C# console application that performs the following: 1) Build a method which reads 3...

    Create a C# console application that performs the following: 1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times). This needs to be its own method. 2) Call this method twice to store 2 local int array variables. 3) Once both arrays are built, write another method which accepts the two arrays and compares the contents to see if they match. If the method...

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