-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path025-Student-Grade-Calculator.java
More file actions
112 lines (84 loc) · 3.05 KB
/
Copy path025-Student-Grade-Calculator.java
File metadata and controls
112 lines (84 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* ============================================================================
* Program Name : Student Grade Calculator
* File Name : 025-Student-Grade-Calculator.java
* Class Name : StudentGradeCalculator
*
* Description:
* This program accepts the marks obtained by a student and calculates
* the corresponding grade using the if-else-if ladder.
*
* Objective:
* - Understand user input using the Scanner class.
* - Learn how to use the if-else-if ladder.
* - Calculate the student's grade based on marks.
*
* Grade Criteria:
* Marks >= 90 : Grade A
* Marks >= 80 : Grade B
* Marks >= 70 : Grade C
* Marks >= 60 : Grade D
* Marks >= 35 : Grade E
* Marks < 35 : Fail
*
* Author : Shaik Mahaboob Basha
* Repository : 01-Core-Java
* Folder : 08-Java-Programs
* ============================================================================
*/
import java.util.Scanner;
public class StudentGradeCalculator {
// The main() method is the entry point of every Java application.
public static void main(String[] args) {
// Create a Scanner object to read input from the keyboard.
Scanner scanner = new Scanner(System.in);
// Ask the user to enter the student's marks.
System.out.print("Enter Student Marks (0 - 100): ");
// Read the marks entered by the user.
int marks = scanner.nextInt();
// Check whether the entered marks are valid.
if (marks < 0 || marks > 100) {
// Display an error message for invalid marks.
System.out.println("Invalid Marks! Please enter marks between 0 and 100.");
// Example Output: Invalid Marks! Please enter marks between 0 and 100.
}
// Check whether the student secured Grade A.
else if (marks >= 90) {
// Display Grade A.
System.out.println("Grade: A");
// Example Output: Grade: A
}
// Check whether the student secured Grade B.
else if (marks >= 80) {
// Display Grade B.
System.out.println("Grade: B");
// Example Output: Grade: B
}
// Check whether the student secured Grade C.
else if (marks >= 70) {
// Display Grade C.
System.out.println("Grade: C");
// Example Output: Grade: C
}
// Check whether the student secured Grade D.
else if (marks >= 60) {
// Display Grade D.
System.out.println("Grade: D");
// Example Output: Grade: D
}
// Check whether the student secured Grade E.
else if (marks >= 35) {
// Display Grade E.
System.out.println("Grade: E");
// Example Output: Grade: E
}
// Execute this block if the student has failed.
else {
// Display the fail result.
System.out.println("Result: Fail");
// Example Output: Result: Fail
}
// Close the Scanner object to release system resources.
scanner.close();
}
}