FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java_Programs/UniversityManagementSystem.java at main · prittoruban/Java_Programs · GitHub
prittoruban
/
Java_Programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java_Programs
/
UniversityManagementSystem.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
107 lines (82 loc) · 2.68 KB
Breadcrumbs
Java_Programs
/
UniversityManagementSystem.java
Copy path
File metadata and controls
107 lines (82 loc) · 2.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
class
Student
{
private
final
String
name
;
private
final
int
id
;
private
final
List
<
Course
>
enrolledCourses
;
public
Student
(
String
name
,
int
id
) {
this
.
name
=
name
;
this
.
id
=
id
;
this
.
enrolledCourses
=
new
ArrayList
<>();
}
public
String
getName
() {
return
name
;
}
public
int
getId
() {
return
id
;
}
public
List
<
Course
>
getEnrolledCourses
() {
return
enrolledCourses
;
}
public
void
enrollCourse
(
Course
course
) {
enrolledCourses
.
add
(
course
);
}
public
void
dropCourse
(
Course
course
) {
enrolledCourses
.
remove
(
course
);
}
public
double
calculateGPA
() {
double
totalCredits
=
0
;
double
totalGradePoints
=
0
;
for
(
Course
course
:
enrolledCourses
) {
totalCredits
+=
course
.
getCredits
();
totalGradePoints
+=
course
.
getCredits
() *
course
.
getGrade
();
}
return
totalGradePoints
/
totalCredits
;
}
}
class
Course
{
private
final
String
courseCode
;
private
final
String
courseName
;
private
final
int
credits
;
private
double
grade
;
public
Course
(
String
courseCode
,
String
courseName
,
int
credits
) {
this
.
courseCode
=
courseCode
;
this
.
courseName
=
courseName
;
this
.
credits
=
credits
;
}
public
String
getCourseCode
() {
return
courseCode
;
}
public
String
getCourseName
() {
return
courseName
;
}
public
int
getCredits
() {
return
credits
;
}
public
double
getGrade
() {
return
grade
;
}
public
void
setGrade
(
double
grade
) {
this
.
grade
=
grade
;
}
}
public
class
UniversityManagementSystem
{
public
static
void
main
(
String
[]
args
) {
// Create courses
Course
mathCourse
=
new
Course
(
"MATH101"
,
"Introduction to Mathematics"
,
3
);
Course
csCourse
=
new
Course
(
"CS101"
,
"Introduction to Computer Science"
,
4
);
// Create students
Student
student1
=
new
Student
(
"Alice"
,
1
);
Student
student2
=
new
Student
(
"Bob"
,
2
);
// Enroll students in courses
student1
.
enrollCourse
(
mathCourse
);
student1
.
enrollCourse
(
csCourse
);
student2
.
enrollCourse
(
mathCourse
);
// Set grades for courses
mathCourse
.
setGrade
(
3.5
);
csCourse
.
setGrade
(
4.0
);
// Display GPA for each student
System
.
out
.
println
(
"GPA for "
+
student1
.
getName
() +
": "
+
student1
.
calculateGPA
());
System
.
out
.
println
(
"GPA for "
+
student2
.
getName
() +
": "
+
student2
.
calculateGPA
());
}
}
Back
|
FazBrowse Home
|
New Git URL