1 / 2100%
package lab3;
/*------------------------------------------------------------
// AUTHOR: Hussain Almohsin
// FILENAME: Lab3.Java
// SPECIFICATION: Final Weighted Total Calculator
// FOR: CSE 110- Lab #3
// TIME SPENT: // 2 Hours
---------------------------------------*/
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
// This scanner is prepared for you to get inputs
//Scanner object sc created for reading input
Scanner sc = new Scanner(System.in);
// Declare three variables for HW, midterm, and final exam grade
double hw = 0 ;
double midterm = 0;
double finalExam = 0;
// Declare a loop control variable
int loopcontrol = 0;
int i = 0;
//loop for inputing each grade
while (i < 3) {
if (i == 0) {
System.out.print("Enter your HOME WORK grade: ");
hw = sc.nextDouble();
//checking enterd value is in the domain or not
if (hw >= 0 && hw <= 100) {
//increment loop variable
i++;
} else {
//prompt to enter a valid grade
System.out.println("[ERR] Invalid input. Homework grade
should be in [0,100]");
}
}
if (i == 1) {
System.out.print("Enter your MID TERM grade: ");
midterm = sc.nextDouble();
//checking enterd value is in the domain or not
if (midterm >= 0 && midterm <= 100) {
//increment loop variable
i++;
} else {
//prompt to enter a valid grade
System.out.println("[ERR] Invalid input.MID TERM grade
should be in [0,100]");
}
}
if (i == 2) {
System.out.print("Enter your FINAL grade: ");
finalExam = sc.nextDouble();
//checking enterd value is in the domain or not
if (finalExam >= 0 && finalExam <= 200) {
//increment loop variable
i++;
} else {
//prompt to enter a valid grade
System.out.println("[ERR] Invalid input.FINAL grade should
be in [0,100]");
}
}
}
//calculating weighted total
int wTotal = (int) ((finalExam / 200 * 50) + (midterm * 0.25) + (hw *
0.25));
//printing weighted total
System.out.println("[INFO] Student's Weighted Total is " + wTotal);
//checking weighted total is greater than or equals to 50
if (wTotal >= 50)
//print PASSED message
System.out.print("[INFO] Student PASSED the class");
else
//print FAILED message
System.out.print("[INFO] Student FAILED the class");
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed