Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having trouble with this assignment, I need to modify my current program(it's a program that calculates the grade for a class) and I can

I'm having trouble with this assignment, I need to modify my current program(it's a program that calculates the grade for a class) and I can only use three loops in the whole program. One do-loop, one while-loop, and one for-each loop. I also need to modify it where the user can keep entering grades for a category until a negative number is entered. Here is a copy of my code (It's in JAVA):

import java.util.Scanner;

public class classGrade {

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 String 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;

//Create scanner Scanner in = new Scanner(System.in); //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-loop to ask the user to continue the program or quit it } while(!conti.equals("continue") && !conti.equals("quit")){ System.out.println("Enter 'continue' or 'quit'"); conti = in.next(); } }while(conti.equals("continue")); } }

-Thank you in advance :)

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

Students also viewed these Databases questions