-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCombinedObjects.java
More file actions
108 lines (78 loc) · 2.64 KB
/
CombinedObjects.java
File metadata and controls
108 lines (78 loc) · 2.64 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
103
104
105
106
107
108
package Online_Code_Samples.Week2;
import java.util.ArrayList;
import java.util.List;
public class CombinedObjects {
private String name;
private String location;
private String courseName;
private List<Student> studentList;
public CombinedObjects(String name, String location, String courseName){
this.name = name;
this.location = location;
this.courseName = courseName;
studentList = new ArrayList<>();
}
public List<Student> getAGradeStudent( List<Student> students, int score ){
List<Student> returnedStudents = new ArrayList<>();
for(Student st: students){
if( st.getScore() >= score ){
returnedStudents.add(st);
}
}
return returnedStudents;
}
public Student getBestStudent( List<Student> students ){
Student best = students.get(0);
for(Student student : students ){
if(student.getScore() > best.getScore()){
best = student;
}
}
return best;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> studentList) {
this.studentList = studentList;
}
public static void main(String[] args) {
Student first = new Student("John", 25, 72);
Student fifth = new Student("John", 25, 35);
Student second = new Student("Jane", 27, 83);
Student third = new Student("David", 35, 68);
Student fourth = new Student("Joy", 30, 95);
CombinedObjects combinedObjects = new CombinedObjects("Java Students", "Ingryd Academy", "Java101");
List<Student> students = new ArrayList<>();
students.add(first);
students.add(second);
students.add(third);
students.add(fourth);
students.add(fifth);
combinedObjects.setStudentList(students);
System.out.println(combinedObjects.getBestStudent(students));
for(Student st: students){
System.out.println(st);
}
List<Student> studentList1 = combinedObjects.getAGradeStudent( combinedObjects.getStudentList(), 70 );
System.out.println(studentList1);
}
}