瀏覽代碼

all classes done, need tests

Nuridalia.Hernandez 5 年之前
父節點
當前提交
c4e97dfc2a

+ 35
- 0
demo/src/main/java/com/example/demo/Classroom.java 查看文件

@@ -0,0 +1,35 @@
1
+package com.example.demo;
2
+
3
+public class Classroom {
4
+    private Instructors instructors;
5
+    private Students students;
6
+    public Classroom(){
7
+
8
+    }
9
+
10
+    public Classroom(Instructors instructors, Students students) {
11
+        this.instructors = instructors;
12
+        this.students = students;
13
+    }
14
+
15
+    public void hostLecture (Teacher teacher, double numbersOfHours){
16
+        teacher.lecture(students,numbersOfHours);
17
+
18
+    }
19
+
20
+    public Instructors getInstructors() {
21
+        return instructors;
22
+    }
23
+
24
+    public void setInstructors(Instructors instructors) {
25
+        this.instructors = instructors;
26
+    }
27
+
28
+    public Students getStudents() {
29
+        return students;
30
+    }
31
+
32
+    public void setStudents(Students students) {
33
+        this.students = students;
34
+    }
35
+}

+ 26
- 0
demo/src/main/java/com/example/demo/ClassroomConfig.java 查看文件

@@ -0,0 +1,26 @@
1
+package com.example.demo;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.context.annotation.DependsOn;
6
+
7
+
8
+@Configuration
9
+public class ClassroomConfig {
10
+
11
+    @Bean(name = "currentCohort")
12
+    @DependsOn({"instructors", "students"})
13
+    public Classroom currentCohort(Instructors instructors , Students students){
14
+    return new Classroom(instructors, students);
15
+    }
16
+
17
+
18
+
19
+    @Bean(name = "previousCohort")
20
+    @DependsOn({"instructors" , "students"})
21
+    public Classroom previousCohort(Instructors instructors, Students students){
22
+        return new Classroom(instructors, students);
23
+
24
+    }
25
+
26
+}

+ 35
- 0
demo/src/main/java/com/example/demo/Instructor.java 查看文件

@@ -0,0 +1,35 @@
1
+package com.example.demo;
2
+
3
+import java.util.Iterator;
4
+
5
+public class Instructor extends Person  implements Teacher{
6
+
7
+
8
+    public Instructor(long id, String name) {
9
+        super(id, name);
10
+
11
+    }
12
+
13
+
14
+    @Override
15
+    public void teach(Learner learner, double numberOfHours) {
16
+        learner.learn (numberOfHours);
17
+
18
+
19
+    }
20
+
21
+    @Override
22
+    public void lecture(Iterable<? extends Learner> learners, double numberOfHours) {
23
+        int count = 0;
24
+        Iterator iterator = learners.iterator();
25
+
26
+        while (iterator.hasNext()){
27
+            count++;
28
+        }
29
+        for (Learner l: learners) {
30
+            l.learn(numberOfHours/count);
31
+
32
+        }
33
+
34
+    }
35
+}

+ 17
- 0
demo/src/main/java/com/example/demo/Instructors.java 查看文件

@@ -0,0 +1,17 @@
1
+package com.example.demo;
2
+
3
+import java.util.Iterator;
4
+
5
+
6
+public class Instructors extends People<Instructor> {
7
+    public Instructors(Instructor ... instructors) {
8
+        super(instructors);
9
+    }
10
+
11
+
12
+
13
+    @Override
14
+    public Iterator<Instructor> iterator() {
15
+        return null;
16
+    }
17
+}

+ 31
- 0
demo/src/main/java/com/example/demo/InstructorsConfig.java 查看文件

@@ -0,0 +1,31 @@
1
+package com.example.demo;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.context.annotation.Primary;
6
+
7
+
8
+@Configuration
9
+public class InstructorsConfig {
10
+
11
+    @Bean(name = "tcUsaInstructors")
12
+    public Instructors tcUsaInstructors() {
13
+        return new Instructors();
14
+    }
15
+
16
+
17
+    @Bean(name = "tcUkInsructors")
18
+    public Instructors tcUkInstrructors (){
19
+
20
+        return new Instructors();
21
+    }
22
+
23
+
24
+
25
+    @Bean(name = "instructors")
26
+    @Primary
27
+    public Instructors ZipCodeInstructors(){
28
+
29
+        return new Instructors();
30
+    }
31
+}

+ 53
- 0
demo/src/main/java/com/example/demo/People.java 查看文件

@@ -0,0 +1,53 @@
1
+package com.example.demo;
2
+
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+import java.util.List;
6
+
7
+public abstract class People <PersonType extends Person> implements Iterable<PersonType>{
8
+     List<PersonType> personList;
9
+
10
+    public People(Person ... people) {
11
+       this.personList = new ArrayList(Arrays.asList(people));
12
+
13
+    }
14
+
15
+    public People() {
16
+
17
+        this.personList = new ArrayList<>();
18
+    }
19
+
20
+    public void add(PersonType person){
21
+        personList.add(person);
22
+    }
23
+    public void remove(PersonType person){
24
+        personList.remove(person);
25
+    }
26
+    public int size(){
27
+
28
+        return personList.size();
29
+    }
30
+    public void clear(){
31
+        personList.clear();
32
+    }
33
+    public void addAll(Iterable<PersonType> personTypeIterable){
34
+        for (PersonType person:personTypeIterable) {
35
+            personList.add(person);
36
+        }
37
+
38
+    }
39
+    public PersonType findById(Long id){
40
+        for (PersonType person: personList) {
41
+            if (person.getId() == id){
42
+                return person;
43
+            }
44
+        }
45
+        return null;
46
+    }
47
+    public List<PersonType> findAll(){
48
+        return personList;
49
+    }
50
+
51
+
52
+
53
+}

+ 2
- 1
demo/src/main/java/com/example/demo/Person.java 查看文件

@@ -4,11 +4,12 @@ public class Person {
4 4
   private final long id;
5 5
   private String name;
6 6
 
7
-    public Person(long id) {
7
+    public Person(long id, String name) {
8 8
         this.id = id;
9 9
         this.name=name;
10 10
     }
11 11
 
12
+
12 13
     public long getId() {
13 14
         return id;
14 15
     }

+ 17
- 7
demo/src/main/java/com/example/demo/Student.java 查看文件

@@ -1,19 +1,29 @@
1 1
 package com.example.demo;
2 2
 
3 3
 public class Student extends Person implements Learner {
4
-   private Double totalStudyTime;
4
+   private double totalStudyTime;
5 5
 
6
-    public Student(long id) {
7
-        super(id);
6
+    public Student(long id, String name) {
7
+        super(id,name);
8
+    }
9
+
10
+    public Student(long id, String name, double totalStudyTime) {
11
+        super(id, name);
12
+        this.totalStudyTime = totalStudyTime;
13
+    }
14
+    public Double getTotalStudyTime() {
15
+        return totalStudyTime;
16
+    }
17
+
18
+    public void setTotalStudyTime(double totalStudyTime) {
19
+        this.totalStudyTime = totalStudyTime;
8 20
     }
9 21
 
10 22
     @Override
11 23
     public void learn(Double numberOfHours) {
12
-        this.totalStudyTime = totalStudyTime+numberOfHours;
24
+        this.totalStudyTime += numberOfHours;
13 25
 
14 26
     }
15 27
 
16
-    public Double getTotalStudyTime() {
17
-        return totalStudyTime;
18
-    }
28
+
19 29
 }

+ 19
- 0
demo/src/main/java/com/example/demo/StudentConfig.java 查看文件

@@ -0,0 +1,19 @@
1
+package com.example.demo;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+
6
+@Configuration
7
+public class StudentConfig {
8
+
9
+    @Bean(name = "students")
10
+    public Students currrentStudents (){
11
+        return new Students();
12
+
13
+    }
14
+    @Bean(name = "previousStudents")
15
+    public Students previousStudents(){
16
+        return new Students();
17
+
18
+    }
19
+}

+ 21
- 0
demo/src/main/java/com/example/demo/Students.java 查看文件

@@ -0,0 +1,21 @@
1
+package com.example.demo;
2
+
3
+import java.util.Iterator;
4
+
5
+public class Students extends People<Student> {
6
+
7
+
8
+
9
+    public Students(Student ... students) {
10
+        super(students);
11
+    }
12
+
13
+    @Override
14
+    public Iterator iterator() {
15
+        return personList.iterator();
16
+    }
17
+
18
+
19
+
20
+
21
+}

+ 1
- 1
demo/src/main/java/com/example/demo/Teacher.java 查看文件

@@ -1,7 +1,7 @@
1 1
 package com.example.demo;
2 2
 
3 3
 public interface Teacher {
4
-    void teach(double numberOfHours);
4
+    void teach(Learner learner,double numberOfHours);
5 5
     void lecture(Iterable<? extends Learner> learners,double numberOfHours);
6 6
 }
7 7
 

+ 16
- 0
demo/src/test/java/com/example/demo/StudentConfTest.java 查看文件

@@ -0,0 +1,16 @@
1
+package com.example.demo;
2
+
3
+import org.junit.runner.RunWith;
4
+import org.springframework.boot.test.context.SpringBootTest;
5
+import org.springframework.test.context.junit4.SpringRunner;
6
+
7
+@RunWith(SpringRunner.class)
8
+@SpringBootTest
9
+public class StudentConfTest {
10
+    Student Student;
11
+    Student prevStudent;
12
+
13
+    
14
+
15
+
16
+}