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

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

  • NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the...

    NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user...

  • Using c++ Write a program that reads in a list of up to 25 first names...

    Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...

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

  • in a java application need  to create an application which prompts the user numerator and denominator values...

    in a java application need  to create an application which prompts the user numerator and denominator values then show the result of the division.  The application will use exception handling to verify the user has entered valid input and will continue to prompt the user for input as long as the value they enter is invalid.  Once the user has entered valid numerator and denominator values, the result is shown and the application exits. had some issues when I entered letters instead of...

  • Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate...

    Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate the weekly paycheck for both Salaried and Hourly employees. Salaried employees will be paid 1/52 of their annual pay minus 18% withheld for federal and state taxes, as well as 4% for retirement pension. Salaried employees do not collect overtime pay. There are two types of Hourly employees; permanent employees and temporary weekly employees. •Permanent weekly employees will be paid their hourly rate minus...

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