-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUGStudent.java
More file actions
27 lines (23 loc) · 793 Bytes
/
Copy pathUGStudent.java
File metadata and controls
27 lines (23 loc) · 793 Bytes
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
// Inherits from Student and implements calculateGrade() based on UG rules
public class UGStudent extends Student {
// Constructor calls base class constructor to initialize fields
public UGStudent(String name, int rollNo, int marks) {
super(name, rollNo, marks);
}
// Calculate grade for UG student
@Override
public char calculateGrade() {
if (marks >= 85) return 'A';
else if (marks >= 70) return 'B';
else if (marks >= 50) return 'C';
else return 'F';
}
// Display UG student details
@Override
public void display() {
System.out.println("UG Student | Name: " + name +
" Roll: " + rollNo +
" Marks: " + marks +
" Grade: " + calculateGrade());
}
}