Create a program that takes in a student’s full names and marks for 3 In-class exercises, then calculate the average of this marks. This average mark is then categorized as follows: Marks obtained Grade Level Message 80 – 100 1 Magnificent!!
70 – 79 2 Excellent!!
60 – 69 3 Good work!!
50 – 59 4 Good!!
0 – 49 0 Fail – Try again next Year!!
Greater than 100 or less than 0 X Invalid Marks!!, Marks too high. Or Invalid Marks!!, Negative marks not allowed.
Sample run 1: Enter student full names: Goodluck Johnathan Enter 3 marks separated by spaces: 78 94.6 88
Output: Student name: Goodluck Johnathan Grade Level: 1 Comment: Magnificent!! Sample run 2: Enter student full names: Ellen Johnson Sirleaf Enter 3 marks separated by spaces: 200 104.87 99.9
Output: Student name: Ellen Johnson Sirleaf Grade Level: X Comment: Invalid Marks!!, Marks too high
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int comment = 1;
while (true) {
System.out.print("Enter student full names: ");
String name = in.nextLine();
System.out.print("Enter 3 marks separated by spaces: ");
double average = 0;
for (int i = 0; i < 3; i++) {
average += in.nextDouble();
}
in.nextLine();
average /= 3;
System.out.print("Student name: " + name + " Grade level: " + comment++ + " Comment: ");
if (average > 100) {
System.out.println("Invalid Marks!!, Marks too high.");
} else if (average < 0) {
System.out.println("Invalid Marks!!, Negative marks not allowed.");
} else if (average >= 80) {
System.out.println("Magnificent!!");
} else if (average >= 70) {
System.out.println("Excellent!!");
} else if (average >= 60) {
System.out.println("Good work!!");
} else if (average >= 50) {
System.out.println("Good!!");
} else {
System.out.println("Try again next Year!!");
}
}
}
}
Comments
Leave a comment