220k views
4 votes
Program MATH_SCORES: Your math instructor gives three tests worth 50 points each. You can drop one of the test scores. The final grade is the sum of the two best test scores. Assuming the three test scores are input from the keyboard, write an interactive program that asks the user to enter three test scores and then calculates the final letter grade using the following cut-off points. >=90 A <90, >=80 B <80, >=70 C <70, >=60 D < 60 F Input validation: Display an error message if the user enters a score greater than 50 and do not accept negative values.

User Mdarwin
by
5.4k points

1 Answer

6 votes

Answer:

import java.util.Scanner;

public class num5 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

//Prompt and receive the three Scores

int score1;

int score2;

int score3;

do {

System.out.println("Enter first Score Enter score between 1 -50");

score1 = in.nextInt();

} while(score1>50 || score1<0);

do {

System.out.println("Enter second Score.The second score must be between 1 -50");

score2 = in.nextInt();

} while(score2>50 || score2<0);

do {

System.out.println("Enter Third Score Third score must between 1 -50");

score3 = in.nextInt();

} while(score3>50 || score3<0);

//Find the minimum of the three to drop

int min, min2, max;

if(score1<score2 && score1<score3){

min = score1;

min2 = score2;

max = score3;

}

else if(score2 < score1 && score2<score3){

min = score2;

min2 = score1;

max = score3;

}

else{

min = score3;

min2 = score1;

max = score2;

}

System.out.println("your entered "+max+", "+min2+" and "+min+" the min is");

int total = max+min2;

System.out.println("Total of the two highest is "+total);

//Finding the grade based on the cut-off points given

if(total>=90){

System.out.println("Grade is A");

}

else if(total>=80){

System.out.println("Grade is B");

}

else if(total>=70){

System.out.println("Grade is C");

}

else if(total>=60){

System.out.println("Grade is D");

}

else{

System.out.println("Grade is F");

}

}

}

Step-by-step explanation:

  • Implemented with Java
  • Use the scanner class to receive user input
  • Use a do.....while loop to validate user input for each of the variables. A valid score must be between 0 and 50 while(score>50 || score<0);
  • Use if and else to find the minimum of the three values and drop
  • Add the two highest numbers
  • use if/else if /else statements to print the corresponding grade
User Mise
by
6.4k points