Question

Complete Programming Assignment Chapter 10. Use program In JAVA ProductCodes.java on pages 446-447, it will provide...

Complete Programming Assignment Chapter 10. Use program In JAVA ProductCodes.java on pages 446-447, it will provide you most of the needed code. You are to design and implement a program that reads a series of 10 integers from user and print the average. Read each integer as a string and convert to integer using Integer.parseInt method. If this process throws a NumberFormatException (not a valid number), catch and handle the exception by printing an error message "Not a valid entry, please enter number again: " and prompting user to enter another number. Continue reading from user until 10 valid numbers are entered. points: (5 points) allow user to enter 10 numbers (entered as Strings "scan.nextLine()") (10 points) loop and check for valid number and repeat until 10 valid numbers ask: "Enter Number # :" (10 points) handling exception (print error message and allow continuing) (5 points) calculate print out average, example "Average for these 10 numbers is: 54" ( deduct 0-5 points) messy code or lack comments ------ ------- -------- sample output ------ ---------- ------- Enter integer 1: 10 Enter integer 2: 20 Enter integer 3: ks Not a valid entry. Please enter again. Enter integer 3: 90sd Not a valid entry. Please enter again. Enter integer 3: 30 Enter integer 4: 40 Enter integer 5: 50 Enter integer 6: ---- Not a valid entry. Please enter again. Enter integer 6: 60 Enter integer 7: 70 Enter integer 8: 80 Enter integer 9: [+8* Not a valid entry. Please enter again. Enter integer 9: 90 Enter integer 10: 100 Average for these 10 numbers is: 55.0 All done!

Homework Answers

Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

import java.util.Scanner;
public class Main
{
public static void main (String [] args)
{
int sum=0;
double avg;
Scanner scan = new Scanner(System.in);
for (int i = 0; i < 10; i++)
{
int num;

System.out.println("Enter integer "+(i+1)+": ");

try
{
num=Integer.parseInt(scan.nextLine());
sum+=num;

}
catch(NumberFormatException numfo)
{
i--;
System.out.println("Not a valid entry.");
}

}
avg=sum/10;
System.out.printf("Average for these 10 numbers is: %.2f\n",avg);

}

}

Kindly revert for any queries

Thanks.

Know the answer?
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
Similar Questions
JAVA (Don't make it too complicated) Write a program that prompts the user for the name...
JAVA (Don't make it too complicated) Write a program that prompts the user for the name of a text file. The file should consist of a sequence of integers, one integer per line. The program will read in each line (using nextLine()), parse it as an int (using Integer.parseInt()), and report the number of values and their average. The average should be computed as a double. Your program should do some basic exception handling: (1) If the file cannot be...
Binary Search Tree Code in Java Write a program that prompts user to enter however many...
Binary Search Tree Code in Java Write a program that prompts user to enter however many numbers they want to add to the binary search tree. Then have the user input numbers until the tree contains that many elements. If the user enters a number that already exists in the tree, then a message should be displayed "Number is already in the tree". Once all elements are added to the tree print its contents in sorted order. Assume all user...
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
Write a complete C++ program asking the user to enter numbers one by one. User enters...
Write a complete C++ program asking the user to enter numbers one by one. User enters only whole numbers 0 and 10. Once the user enters 0, then the program should print sum of only odd numbers entered by user prior to 0. A valid scenario given below: Enter a number: 5 Enter a number: 3 Enter a number: 2 Enter a number: 3 Enter a number: 8 Enter a number: 0 Sum of the odd numbers you entered is...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
Write a java program that creates an integer array with 50 random values, prompts the user...
Write a java program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. “Out of Bounds”) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs,...
In JAVA For practice using exceptions, this exercise will use a try/catch block to validate integer...
In JAVA For practice using exceptions, this exercise will use a try/catch block to validate integer input from a user. Write a brief program to test the user input. Use a try/catch block, request user entry of an integer, use Scanner to read the input, throw an InputMismatchException if the input is not valid, and display "This is an invalid entry, please enter an integer" when an exception is thrown. InputMismatchException is one of the existing Java exceptions thrown by...
Provide Python code that does the following: 4) Write a program that asks the user to...
Provide Python code that does the following: 4) Write a program that asks the user to enter a 9 character password. Test to see if it is a valid password. The validity test is a) they enter exactly 9 characters AND b) that every 3rd character, starting with the 1st character is the letter z. If it is valid print out the message “valid password” otherwise print the message “invalid password”. Sample output. Please enter a password: zaazbbz12 valid password...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT