-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasestudy5,java
More file actions
92 lines (68 loc) · 1.82 KB
/
Copy pathcasestudy5,java
File metadata and controls
92 lines (68 loc) · 1.82 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
import java.util.ArrayList;
class Learner {
String studentName;
ArrayList<Double> marks;
Learner(String studentName) {
this.studentName = studentName;
marks = new ArrayList<>();
}
void addMark(double mark) {
marks.add(mark);
}
double getAverage() {
if (marks.size() == 0) {
return 0;
}
double total = 0;
for (double m : marks) {
total += m;
}
return total / marks.size();
}
void showDetails() {
System.out.println("Name: " + studentName);
System.out.println("Marks: " + marks);
System.out.println("Average: " + getAverage());
System.out.println("-------------------");
}
}
class ResultSystem {
ArrayList<Learner> learnerList = new ArrayList<>();
void addLearner(Learner l) {
learnerList.add(l);
}
Learner searchByName(String name) {
for (Learner l : learnerList) {
if (l.studentName.equalsIgnoreCase(name)) {
return l;
}
}
return null;
}
void showAll() {
for (Learner l : learnerList) {
l.showDetails();
}
}
}
public class casestudy5 {
public static void main(String[] args) {
ResultSystem system = new ResultSystem();
Learner l1 = new Learner("Arjun");
Learner l2 = new Learner("Sneha");
system.addLearner(l1);
system.addLearner(l2);
l1.addMark(85);
l1.addMark(92);
l2.addMark(78);
l2.addMark(88);
system.showAll();
Learner found = system.searchByName("Arjun");
if (found != null) {
System.out.println("Learner Found:");
found.showDetails();
} else {
System.out.println("Not Found");
}
}
}