Repository navigation
Expand file tree
/
Copy pathStudentGrade.java
More file actions
77 lines (69 loc) · 2.15 KB
/
Copy pathStudentGrade.java
File metadata and controls
77 lines (69 loc) · 2.15 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
import java.util.*;
public class StudentGrade {
String name;
int roll_no;
String subjects;
double marks;
double totalMarks;
double Percentage;
String grade;
String result;
public StudentGrade(String name, int roll_no, double marks, double totalMarks) {
this.name = name;
this.roll_no = roll_no;
this.marks = marks;
this.totalMarks = totalMarks;
}
void calculatePercentage(){
Percentage = (marks/totalMarks)*100;
}
void calculateGrade(){
if (Percentage >= 90){
grade = "A+";
result = "Pass";
}
else if (Percentage >= 80){
grade = "A";
result = "Pass";
}
else if (Percentage >= 70 && Percentage < 80){
grade = "B";
result = "Pass";
}
else if (Percentage >= 60 && Percentage < 70){
grade = "C";
result = "Pass";
}
else if (Percentage < 60 && Percentage >= 50){
grade = "D";
result = "Pass";
}else{
grade = "F";
result = "Fail";
}
}
void Display(){
System.out.println("Student report card!....");
System.out.println("Name : " + name);
System.out.println("Roll_no : " + roll_no);
System.out.println("Marks : " + marks);
System.out.println("Percentage : " + Percentage + "%");
System.out.println("Grade : " + grade);
System.out.println("result : " + result);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("enter student name :");
String name = sc.nextLine();
System.out.print("enter student roll_no :");
int roll_no = sc.nextInt();
System.out.print("enter student marks :");
double marks = sc.nextDouble();
System.out.print("enter student totaMarks :");
double totalMarks = sc.nextDouble();
StudentGrade s1 = new StudentGrade(name, roll_no, marks, totalMarks);
s1.calculatePercentage();
s1.calculateGrade();
s1.Display();
}
}