Answer to Question #245354 in Java | JSP | JSF for Selma

Question #245354
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.
1
Expert's answer
2021-10-01T16:52:38-0400
import java.util.Scanner;


public class StudentsMarks {


	public static void main(String[] args) {
		String studentName = " ";
		int sum = 0;
		double average = 0;
		double[] score = new double[3];
		Scanner input = new Scanner(System.in);
		Scanner scan = new Scanner(System.in);
		System.out.println("Enter student full names and press Enter: ");
		studentName = input.nextLine();
		System.out.println("Enter 3 marks separated by spaces and press Enter: ");
		for (int i = 0; i < score.length; i++) {
			score[i] = scan.nextDouble();
		}
		for (int i = 0; i < score.length; i++) {
			sum += score[i];
		}
		average = sum / 3;
		int avg = (int) average;
		if (avg >= 101) {
			System.out.println("Student name: "+studentName+"Grade Level: X Comment: Invalid Marks!!, Marks too high.");
		} else if (avg >= 80 || avg <= 100) {
			System.out.println("Student name: "+studentName+" 1 Magnificent!!");
		} else if (avg >= 70 || avg <= 79) {
			System.out.println("Student name: "+studentName+" 2 Excellent!!");
		} else if (avg >= 60 || avg <= 69) {
			System.out.println("Student name: "+studentName+" 3 Good work!!");
		} else if (avg >= 50 || avg <= 59) {
			System.out.println("Student name: "+studentName+" 4 Good!!");
		} else if (avg >= 0 || avg <= 49) {
			System.out.println("Student name: "+studentName+" 0 Fail – Try again next Year!!");
		} else if (avg >= 101) {
			System.out.println("Grade Level: X Comment: Invalid Marks!!, Marks too high.");
		}
		input.close();
		scan.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS