Skip to content

Commit 812e617

Browse files
committed
Afternoon Lambda Lab 2
1 parent 2b3ebbf commit 812e617

7 files changed

Lines changed: 31 additions & 8 deletions

File tree

Capture 4.png

3.51 MB
Loading

Capture 5.png

3.36 MB
Loading

Capture 6.png

3.47 MB
Loading

Capture 7.png

3.34 MB
Loading

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<version>1.0-SNAPSHOT</version>
1010

1111
<properties>
12-
<maven.compiler.source>16</maven.compiler.source>
13-
<maven.compiler.target>16</maven.compiler.target>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
1414
</properties>
1515

1616
</project>

src/main/java/students2/School.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,37 @@
44

55
import java.lang.reflect.Method;
66
import java.util.ArrayList;
7+
import java.util.Arrays;
78
import java.util.List;
89

910
interface Criterion<E> {
1011
boolean test(E s);
1112
}
1213

14+
interface Something<E> {
15+
void doSomething(E e);
16+
}
17+
18+
class PrintSomething implements Something<Student> {
19+
@Override
20+
public void doSomething(Student student) {
21+
System.out.println("> " + student);
22+
}
23+
}
24+
1325
public class School {
14-
public static <E> void showAll(List<E> ls) {
26+
// public static <E> void showAll(Iterable<E> ls) {
27+
// for (E s : ls) {
28+
// System.out.println("> " + s);
29+
// }
30+
// System.out.println("---------------------------");
31+
// }
32+
public static <E> void withEvery(Iterable<E> ls, Something<E> someObject) {
1533
for (E s : ls) {
16-
System.out.println("> " + s);
34+
someObject.doSomething(s);
1735
}
18-
System.out.println("---------------------------");
1936
}
37+
2038
public static <E> List<E> getByCriterion(Iterable<E> ls, Criterion<E> crit) {
2139
List<E> res = new ArrayList<>();
2240
for (E s : ls) {
@@ -34,15 +52,19 @@ public static void main(String[] args) {
3452
Student.of("Sheila", 3.9, "Math", "Physics", "Quantum Mechanics", "Astrophysics")
3553
);
3654

37-
showAll(roster);
55+
withEvery(roster, x -> System.out.println("> " + x));
56+
// withEvery(roster, (Student student) -> {
57+
// System.out.println("> " + student);
58+
// });
3859

3960
// show smart students
4061
// showAll(getByCriterion(roster, ???));
4162

4263
// show unenthusiastic students
4364
// showAll(getByCriterion(roster, ???));
4465

45-
List<String> names = List.of("Alex", "James", "Fred", "Susan", "Bill");
66+
// List<String> names = List.of("Alex", "James", "Fred", "Susan", "Bill");
67+
List<String> names = Arrays.asList("Alex", "James", "Fred", "Susan", "Bill");
4668

4769
// show long names
4870
// showAll(getByCriterion(names, ???));

src/main/java/students2/Student.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ private Student(String name, double gpa, String ... courses) {
2020
if (!isValidStudent(name, gpa)) throw new IllegalArgumentException();
2121
this.name = name;
2222
this.gpa = gpa;
23-
this.courses = List.of(courses);
23+
// this.courses = List.of(courses);
24+
this.courses = Arrays.asList(courses);
2425
}
2526

2627
public static boolean isValidStudent(String name, double gpa) {

0 commit comments

Comments
 (0)