-
Notifications
You must be signed in to change notification settings - Fork 21
/
examination_marking_system.java
112 lines (96 loc) · 3.14 KB
/
examination_marking_system.java
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
import java.util.*;
public class examination_marking_system {
public static void main(String[] args) {
Result Ned = new Result("Ned", 20, 3, "Math", true, true, 30);
Ned.displayResult();
System.out.println("");
Result Sam = new Result("Sam", 19, 1, "Physics", false, false, 27);
Sam.displayResult();
System.out.println("");
Result John = new Result("John", 45, 2, "Math", true, false, 34);
John.displayResult();
}
}
// interface for defining the rewards and penalty marks
interface Achievement {
static int grace = 10;
static int penalty = -5;
}
// Registration class, serves as the superclass for Student
abstract class Registration {
public String name;
public int year;
public String subject;
abstract void displayStudent();
}
// once registered, a professor and roll number is assigned. Student class
// is the subclass of registration
class Student extends Registration {
// Professor XYZ is assigned for math course
// Professor ABC is assigned otherwise
public String professor;
public int roll;
public void assignProf() {
if (subject == "Math")
professor = "XYZ";
else
professor = "ABC";
}
// method to view information about the student
public void displayStudent() {
System.out.println(name);
System.out.println("Roll no.: " + roll);
System.out.println("Current year: " + year);
System.out.println("Subject: " + subject);
System.out.println("Professor: " + professor);
}
}
// The Subclass of Student, Examprofile serves as a class to
// confirm if a student has achievement or penalties to be added
// to the result
class ExamProfile extends Student {
public boolean achieved;
public boolean punished;
public int score;
// method to view score of the student in exam
public void showScore() {
System.out.println("Score in exam: " + score);
if (punished)
System.out.println("Penalty deducted");
else if (achieved)
System.out.println("Achievement grace added");
}
}
// Result calculates the final marks obtained by the student
class Result extends ExamProfile implements Achievement {
public int marks;
// constructor
Result(String name, int roll, int year, String subject, boolean achieved, boolean punished, int score) {
this.name = name;
this.roll = roll;
this.year = year;
this.subject = subject;
this.achieved = achieved;
this.punished = punished;
this.score = score;
}
// method to calculate the final marks scored by the student
public void calculatedResult() {
if (punished) {
marks = score + penalty;
} else if (achieved) {
marks = score + grace;
} else {
marks = score;
}
}
// method to display the final result of the student
public void displayResult() {
assignProf();
displayStudent();
showScore();
calculatedResult();
System.out.print("Total Marks: ");
System.out.println(marks);
}
}