-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstudent.java
More file actions
57 lines (52 loc) · 1.38 KB
/
student.java
File metadata and controls
57 lines (52 loc) · 1.38 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
package classObject;
import java.util.Scanner;
class student {
// data members
int roll, std;
String name;
float marks; // total=500, obtained = marks;
char grade;
// member functions
void getStudentInfo() {
System.out.println();
Scanner s = new Scanner(System.in);
System.out.print("enter the roll number: ");
roll = s.nextInt();
s.nextLine(); // used to clear the buffer after the nextInt() so that the next String input
// can be taken without fail.
System.out.print("enter the name of the student: ");
name = s.nextLine();
System.out.print("class: ");
std = s.nextInt();
System.out.print("Marks obtained(out of 500): ");
marks = s.nextFloat();
calcGrade(marks);
s.close();
}
void calcGrade(float marks) {
float perc = marks / 5;
if (perc >= 91 && perc <= 100)
grade = 'O';
else if (perc >= 81 && perc <= 90)
grade = 'E';
else if (perc >= 71 && perc <= 80)
grade = 'A';
else if (perc >= 61 && perc <= 70)
grade = 'B';
else if (perc >= 51 && perc <= 60)
grade = 'C';
else if (perc >= 41 && perc <= 50)
grade = 'D';
else if (perc <= 40 && perc >= 0)
grade = 'F';
else {
System.out.println("wrong marks");
System.exit(0);
}
}
void displayStudentInfo() {
System.out.println();
System.out.print("NAME: " + name + "\t CLASS: " + std + "\t ROLL NO.: " + roll + "\nMARKS: " + marks
+ "\t GRADE: " + grade + "\n");
}
}