Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will use only 3 loops. 1. Do loop 2. While loop 3 For Each loop Modify this program below to produce the same output,

You will use only 3 loops.

1. Do loop

2. While loop

3 For Each loop

Modify this program below to produce the same output, but only use 3 loops in the entire program. Do not ask for number of grades to enter, keep entering grades for a category until a negative number is entered.

import java.util.Scanner; public class AnotherModify { public static void main(String[] args){ //Grades double grade[] = new double[4]; double finalGrade; //Categories double Programming; double Homework; double Labs; double Quizzes; double Readings; double exam[] = new double[3]; double finalExam; double total; //Create scanner Scanner in = new Scanner(System.in); String conti = ""; do{ //Categories' weight double programmingWeight = .15; double homeworkWeight = .10; double labsWeight = .05; double quizzesWeight = .10; double readingsWeight = .10; double exam1Weight = .05; double exam2Weight = .10; double exam3Weight = .15; double finalWeight = .20; //Asking user to input grades System.out.println("Enter grades: "); for(int i=0;i<4;i++){ grade[i] = in.nextDouble(); } finalGrade = in.nextDouble(); System.out.println("Enter five grades from programming assignments: "); for(int i=0;i<4;i++){ grade[i] = in.nextDouble(); } finalGrade = in.nextDouble(); double gradeSum=0; for(int i=0;i<4;i++){ gradeSum += grade[i]; } Programming = (gradeSum + finalGrade)/5; System.out.print("Average of programming assignments: "); System.out.println(Programming); Programming = Programming * programmingWeight; System.out.print("Weight of programming assigments: "); System.out.println(Programming); System.out.println(" "); System.out.println("Enter five grades from homework assignments: "); for(int i=0;i<4;i++){ grade[i] = in.nextDouble(); } finalGrade = in.nextDouble(); gradeSum=0; for(int i=0;i<4;i++){ gradeSum += grade[i]; } Homework = (gradeSum + finalGrade)/5; System.out.print("Average of homework assignments: "); System.out.println(Homework); Homework = Homework * homeworkWeight; System.out.print("Weight of homework assignments: "); System.out.println(Homework); System.out.println(" "); System.out.println("Enter five grades from lab assignments: "); for(int i=0;i<4;i++){ grade[i] = in.nextDouble(); } finalGrade = in.nextDouble(); gradeSum=0; for(int i=0;i<4;i++){ gradeSum += grade[i]; } Labs = (gradeSum + finalGrade)/5; System.out.print("Average of labs assignments: "); System.out.println(Labs); Labs = Labs * labsWeight; System.out.print("Weight of labs assignments: "); System.out.println(Labs); System.out.println(" "); System.out.println("Enter five grades from quiz assignments: "); for(int i=0;i<4;i++){ grade[i] = in.nextDouble(); } finalGrade = in.nextDouble(); gradeSum=0; for(int i=0;i<4;i++){ gradeSum += grade[i]; } Quizzes = (gradeSum+ finalGrade)/5; System.out.print("Average of quiz assignments: "); System.out.println(Quizzes); Quizzes = Quizzes * quizzesWeight; System.out.print("Weight of quiz assignments: "); System.out.println(Quizzes); System.out.println(" "); System.out.println("Enter five grades from reading assignments: "); for(int i=0;i<4;i++){ grade[i] = in.nextDouble(); } finalGrade = in.nextDouble(); gradeSum=0; for(int i=0;i<4;i++){ gradeSum += grade[i]; } Readings = (gradeSum + finalGrade)/5; System.out.print("Average of reading assignments: "); System.out.println(Readings); Readings = Readings * readingsWeight; System.out.print("Weight of reading assignments: "); System.out.println(Readings); double examSum=0; for(int i=0;i<3;i++){ System.out.println(" "); System.out.println("Enter exam "+(i+1)+": "); exam[i] = in.nextDouble(); exam[i] = exam[i] * exam1Weight; examSum +=exam[i]; System.out.println("Exam "+(i+1)+" weight: "+exam[i]); } System.out.println("Enter final exam: "); finalExam = in.nextDouble(); finalExam = finalExam * finalWeight; System.out.println("Final exam weight: "+finalExam); total = Programming + Homework + Labs + Quizzes + Readings + examSum + finalExam; System.out.println(" "); System.out.println("Grade for class: "+total); /* * In this part of the program, a switch statement will be used to display the letter grade */ //Asking user to input grade for the class from the result of the final grade System.out.print("Enter the grade you got for the class: "); int Grade = (int)in.nextDouble(); //Switch statement is created to display letter grade switch (Grade/10) { //Grade from 100 to 90 case 10: case 9: System.out.println("Your grade is a A."); break; //Grade from 89 to 80 case 8: System.out.println("Your grade is a B."); break; //Grade from 79 to 70 case 7: System.out.println("Your grade is a C."); break; //Grade from 69 to 60 case 6: System.out.println("Your grade is a D."); break; //Grade less than 60 default: System.out.println("Your grade is a F."); } while(!conti.equals("continue") && !conti.equals("quit")){ System.out.println("Enter 'continue' or 'quit'"); conti = in.next(); } }while(conti.equals("continue")); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions