Question: Someone please help me! I need the code to read my inputs for homework Midtrm, and Finl but they are stuck within my nested loops.
Someone please help me! I need the code to read my inputs for homework Midtrm, and Finl but they are stuck within my nested loops. I tried using "Final" variables and that did not work. Please show me how to solve this (preferably with steps/comments) and I will rate for a correct answer!
Code:
import java.util.Scanner; public class Lab3 { public static void main(String[] args) { // This scanner is prepared for you to get inputs Scanner scan = new Scanner(System.in); //set up the i value System.out.println("Enter 1 to input the homework, 2 to input the midtrm grade, and 2 to input the final grade"); int i = scan.nextInt(); //Start the while loop while (i > -1 || i < 3) { //Nest if loops to input homework, midtrm, and finl grades: //HW Inputs if (i == 0) { System.out.println("Enter the homework grade/points: "); int HW = scan.nextInt(); final double homework = HW; //Catch invalid inputs if (HW >= 0 || HW <= 100) { System.out.println("The entered homework grade was: " + HW); } else { System.out.println("The entered homework grade was invalid, please try again"); } } //Midtrm Inputs if (i == 1) { System.out.println("Enter the MidTrm grade/points: "); int MidTrm = scan.nextInt(); //Catch invalid inputs if (MidTrm >= 0 || MidTrm <= 100) { System.out.println("The entered midtrm grade was: " + MidTrm); } else { System.out.println("The entered midtrm grade was invalid, please try again"); } } else if (i ==2) { System.out.println("Enter the Finl grade/points: "); int Finl = scan.nextInt(); //Catch invalid inputs if (Finl >= 0 || Finl <= 200) { System.out.println("The entered finl grade was: " + Finl); } else { System.out.println("The entered finl grade was invalid, please try again"); } } double Total = homework * 0.25 + MidTrm*0.25 + Finl*0.5; double weighted_total = (Total); if (weighted_total > 50) { System.out.println("The student PASSED the class."); } else { System.out.println("The student FAILED the class."); } scan.close(); } } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
