-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
102 lines (77 loc) · 2.35 KB
/
Course.java
File metadata and controls
102 lines (77 loc) · 2.35 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
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
public class Student{
private String name;
private int id;
private ArrayList courses;
public Student(String name, int id){
this.name=name;
this.id=id;
courses= new ArrayList();
}
public void addCourse(Course course){
courses.add(course);
}
public void removeCourse(Course course){
courses.remove(course);
}
public ArrayList getCourses(){
return courses;
}
public double getGPA(){
double total=0;
int count=0;
for( Course course : courses){
total += courses.getGrade();
count++;
}
public String getTranscript() {
String transcript= "Name : " + name + "\n" ;
transcript += "ID : "+ id + "\n";
for ( Course course : courses){
transcript += "Course: " + course.getName() + " (" + course.getCredits() + " credits)\n";
transcript += "Grade: " + course.getGrade() + " (" + course.getLetterGrade() + " )\n";
}
return transcript
}
System.out.println( "The Average Grade :- " + total/count);
}
}
public class Course{
private String name;
private int credits;
private double grade;
public Course(String name, int credits){
this.name=name;
this.credits=credits;
}
public void setGrade(double grade){
this.grade=grade;
}
public double getGrade(){
return grade;
}
public int getCredits(){
return credits;
}
}
public class Student{
public static void main(String[] args){
Course cs= new Course("Computer Science", 4);
cs.setGrade(3.7);
Course mt = new Course("Math", 3);
mt.setGrade(4);
Student Alice= new Student("Alice", 1234);
Alice.addCourse(cs);
Alice.addCourse(mt);
System.out.println(Alice.getGPA());
System.out.println(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
Course cs2= new Course("Computer Science", 4);
cs2.setGrade(3);
Course mt2 = new Course("Math", 3);
mt2.setGrade(3.5);
Student Bob= new Student("Alice", 5678);
Bob.addCourse(cs2);
Bob.addCourse(mt2);
System.out.println(Bob.getGPA());
System.out.println(Bob.getTranscript());
}
}