-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
84 lines (75 loc) · 2.62 KB
/
Student.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
import java.util.Scanner;
class Student {
private String name;
private String rollNo;
private int semester;
private String course;
private int marks;
private char grade;
// Default constructor
public Student() {
name = "";
rollNo = "";
semester = 0;
course = "";
marks = 0;
grade = 'F';
}
// Parameterized constructor
public Student(String name, String rollNo, int semester, String course, int marks) {
this.name = name;
this.rollNo = rollNo;
this.semester = semester;
this.course = course;
this.marks = marks;
grade = calculateGrade(marks);
}
// Method to get student data from user
public void getStudentData() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter student name: ");
name = scanner.nextLine();
System.out.print("Enter roll no.: ");
rollNo = scanner.nextLine();
System.out.print("Enter semester no.: ");
semester = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter course name: ");
course = scanner.nextLine();
System.out.print("Enter marks: ");
marks = scanner.nextInt();
grade = calculateGrade(marks);
scanner.close();
}
// Method to calculate grade
private char calculateGrade(int marks) {
if (marks >= 90) return 'A';
else if (marks >= 80) return 'B';
else if (marks >= 70) return 'C';
else if (marks >= 60) return 'D';
else return 'F';
}
// Method to display
public void displayQuizGrade() {
System.out.println("Student Name: " + name);
System.out.println("Roll No.: " + rollNo);
System.out.println("Semester No.: " + semester);
System.out.println("Course Name: " + course);
System.out.println("Marks: " + marks);
System.out.println("Grade: " + grade);
}
// Main method
public static void main(String[] args) {
System.out.println("Enter student1 data");
Student student1 = new Student();
student1.getStudentData();
Student student2 = new Student("Areeba", "FA18-RCS-011-Section (B)", 3, "Data Structures", 85);
Student student3 = new Student("Wardah", "FA18-RCS-012-Section (C)", 4, "Algorithms", 72);
System.out.println("\nStudent 1 Details:");
student1.displayQuizGrade();
System.out.println("\nStudent 2 Details:");
student2.displayQuizGrade();
System.out.println("\nStudent 3 Details:");
student3.displayQuizGrade();
}
}