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!
`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.
Get Answers For Free
Most questions answered within 1 hours.