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