-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP-prob-2.java
More file actions
49 lines (43 loc) · 1.66 KB
/
OOP-prob-2.java
File metadata and controls
49 lines (43 loc) · 1.66 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
public class Student {
// Private fields for student information and grades
private String name;
private int rollNumber;
private double grade1, grade2;
// Constructor to initialize the student's name, roll number, and two grades
public Student(String name, int rollNumber, double grade1, double grade2) {
this.name = name;
this.rollNumber = rollNumber;
this.grade1 = grade1;
this.grade2 = grade2;
}
// Method to calculate the average of the two grades
public double calculateAverage() {
return (grade1 + grade2) / 2.0;
}
// Method to determine the grade status based on the average
public String determineStatus() {
double average = calculateAverage();
if (average >= 90) {
return "Excellent";
} else if (average >= 75) {
return "Good";
} else if (average >= 50) {
return "Pass";
} else {
return "Fail";
}
}
// Method to display all student information, grades, and status
public void displayStudentInfo() {
System.out.println("Student Name: " + name);
System.out.println("Roll Number: " + rollNumber);
System.out.println("Grades: " + grade1 + ", " + grade2 );
System.out.println("Average Grade: " + calculateAverage());
System.out.println("Grade Status: " + determineStatus());
}
// Main method to create a Student object and display its information
public static void main(String[] args) {
Student student1 = new Student("abc", 101, 85, 78, 92); // Note: Constructor only accepts 4 arguments
student1.displayStudentInfo();
}
}