From 3f0dff8b8075589e2c1ba14b032e7507c44872b4 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 09:34:53 +0100 Subject: [PATCH 01/81] original commit --- .idea/Iron-hack-school.iml | 9 +++ Ironhack-school/.gitignore | 38 ++++++++++ Ironhack-school/.idea/encodings.xml | 7 ++ Ironhack-school/.idea/misc.xml | 15 ++++ Ironhack-school/.idea/vcs.xml | 6 ++ Ironhack-school/.idea/workspace.xml | 70 +++++++++++++++++++ Ironhack-school/pom.xml | 25 +++++++ .../src/main/java/ironhack/com/App.java | 13 ++++ .../src/main/java/ironhack/com/Course.java | 4 ++ .../src/test/java/ironhack/com/AppTest.java | 38 ++++++++++ 10 files changed, 225 insertions(+) create mode 100644 .idea/Iron-hack-school.iml create mode 100644 Ironhack-school/.gitignore create mode 100644 Ironhack-school/.idea/encodings.xml create mode 100644 Ironhack-school/.idea/misc.xml create mode 100644 Ironhack-school/.idea/vcs.xml create mode 100644 Ironhack-school/.idea/workspace.xml create mode 100644 Ironhack-school/pom.xml create mode 100644 Ironhack-school/src/main/java/ironhack/com/App.java create mode 100644 Ironhack-school/src/main/java/ironhack/com/Course.java create mode 100644 Ironhack-school/src/test/java/ironhack/com/AppTest.java diff --git a/.idea/Iron-hack-school.iml b/.idea/Iron-hack-school.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Iron-hack-school.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Ironhack-school/.gitignore b/Ironhack-school/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/Ironhack-school/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Ironhack-school/.idea/encodings.xml b/Ironhack-school/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Ironhack-school/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Ironhack-school/.idea/misc.xml b/Ironhack-school/.idea/misc.xml new file mode 100644 index 0000000..cb7de09 --- /dev/null +++ b/Ironhack-school/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Ironhack-school/.idea/vcs.xml b/Ironhack-school/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Ironhack-school/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Ironhack-school/.idea/workspace.xml b/Ironhack-school/.idea/workspace.xml new file mode 100644 index 0000000..16d51eb --- /dev/null +++ b/Ironhack-school/.idea/workspace.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1708762591629 + + + + \ No newline at end of file diff --git a/Ironhack-school/pom.xml b/Ironhack-school/pom.xml new file mode 100644 index 0000000..b0956ad --- /dev/null +++ b/Ironhack-school/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + ironhack.com + Ironhack-school + 1.0-SNAPSHOT + jar + + Ironhack-school + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java new file mode 100644 index 0000000..f3ce3f5 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/App.java @@ -0,0 +1,13 @@ +package ironhack.com; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java new file mode 100644 index 0000000..3402005 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -0,0 +1,4 @@ +package ironhack.com; + +public class Course { +} diff --git a/Ironhack-school/src/test/java/ironhack/com/AppTest.java b/Ironhack-school/src/test/java/ironhack/com/AppTest.java new file mode 100644 index 0000000..4ab5d69 --- /dev/null +++ b/Ironhack-school/src/test/java/ironhack/com/AppTest.java @@ -0,0 +1,38 @@ +package ironhack.com; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} From 044a8354a4c6d457e2f643e242712974cd37313f Mon Sep 17 00:00:00 2001 From: katalinjordans Date: Sat, 24 Feb 2024 12:25:25 +0100 Subject: [PATCH 02/81] Creation of schema --- Ironhack-school/pom.xml | 6 ++++ .../src/main/java/ironhack/com/App.java | 4 --- .../src/main/java/ironhack/com/Course.java | 14 ++++++++ .../src/main/java/ironhack/com/Person.java | 10 ++++++ .../src/main/java/ironhack/com/School.java | 34 +++++++++++++++++++ .../src/main/java/ironhack/com/Student.java | 12 +++++++ .../src/main/java/ironhack/com/Teacher.java | 9 +++++ .../src/main/java/ironhack/com/Utils.java | 9 +++++ 8 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 Ironhack-school/src/main/java/ironhack/com/Person.java create mode 100644 Ironhack-school/src/main/java/ironhack/com/School.java create mode 100644 Ironhack-school/src/main/java/ironhack/com/Student.java create mode 100644 Ironhack-school/src/main/java/ironhack/com/Teacher.java create mode 100644 Ironhack-school/src/main/java/ironhack/com/Utils.java diff --git a/Ironhack-school/pom.xml b/Ironhack-school/pom.xml index b0956ad..e1c033e 100644 --- a/Ironhack-school/pom.xml +++ b/Ironhack-school/pom.xml @@ -21,5 +21,11 @@ 3.8.1 test + + org.projectlombok + lombok + 1.18.30 + provided + diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java index f3ce3f5..30f12c6 100644 --- a/Ironhack-school/src/main/java/ironhack/com/App.java +++ b/Ironhack-school/src/main/java/ironhack/com/App.java @@ -1,9 +1,5 @@ package ironhack.com; -/** - * Hello world! - * - */ public class App { public static void main( String[] args ) diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java index 3402005..76e33e4 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Course.java +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -1,4 +1,18 @@ package ironhack.com; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter public class Course { + private String Id; + private String name; + private double price; + private double money_earned; + private Teacher teacher; + + public void assign(String teacherId) { + // logica + } } diff --git a/Ironhack-school/src/main/java/ironhack/com/Person.java b/Ironhack-school/src/main/java/ironhack/com/Person.java new file mode 100644 index 0000000..52d65e9 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/Person.java @@ -0,0 +1,10 @@ +package ironhack.com; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public abstract class Person { + private String id; + private String name; +} diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java new file mode 100644 index 0000000..6029563 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -0,0 +1,34 @@ +package ironhack.com; +import java.util.List; + +public class School { + private List studentList; + private List teacherList; + private List courseList; + + private void showStudents() { + // codigo + } + + private Student lookupStudent(String studentId) { + return null; + } + + private void showCourses() { + // codigo + } + + private Course lookupCourse(String courseId) { + return null; + } + + private void showTeachers() { + // codigo + } + + private Teacher lookupTeacher(String teacherId) { + return null; + } + + +} diff --git a/Ironhack-school/src/main/java/ironhack/com/Student.java b/Ironhack-school/src/main/java/ironhack/com/Student.java new file mode 100644 index 0000000..7078b7c --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/Student.java @@ -0,0 +1,12 @@ +package ironhack.com; +import lombok.Getter; +import lombok.Setter; +import java.util.List; + +@Getter +@Setter +public class Student extends Person{ + private String address; + private String email; + private List courseList; +} diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java new file mode 100644 index 0000000..10f0b0a --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -0,0 +1,9 @@ +package ironhack.com; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Teacher { + private double salary; +} diff --git a/Ironhack-school/src/main/java/ironhack/com/Utils.java b/Ironhack-school/src/main/java/ironhack/com/Utils.java new file mode 100644 index 0000000..6c61a93 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/Utils.java @@ -0,0 +1,9 @@ +package ironhack.com; + +public class Utils { + + public String generateSerialId () { + //logica + return null; + } +} From 6de7e6a9ee5ac4a6df191d2547f6cb7c7ee2f2a5 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Sat, 24 Feb 2024 12:54:30 +0100 Subject: [PATCH 03/81] added logic in generateSerialId method --- Ironhack-school/src/main/java/ironhack/com/Utils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Utils.java b/Ironhack-school/src/main/java/ironhack/com/Utils.java index 6c61a93..56d8b1e 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Utils.java +++ b/Ironhack-school/src/main/java/ironhack/com/Utils.java @@ -1,9 +1,9 @@ package ironhack.com; +import java.util.UUID; public class Utils { public String generateSerialId () { - //logica - return null; + return UUID.randomUUID().toString(); } } From eb488f7e561f8a47d2b20e6f32f1fe965019c800 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 13:01:56 +0100 Subject: [PATCH 04/81] add constructor to class course --- .../src/main/java/ironhack/com/Course.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java index 76e33e4..fa4596b 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Course.java +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -12,7 +12,16 @@ public class Course { private double money_earned; private Teacher teacher; + public void course(String name, double price){ + super(name); + setPrice(price); + } + public void course(String name, double price,Teacher teacher){ + super(name); + setPrice(price); + setTeacher(teacher); + } public void assign(String teacherId) { - // logica + setTeacher(); } } From 96b4702128f3a5b252a62320d55ec4ab808dbf03 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 13:09:05 +0100 Subject: [PATCH 05/81] utils should be static --- Ironhack-school/src/main/java/ironhack/com/Utils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Utils.java b/Ironhack-school/src/main/java/ironhack/com/Utils.java index 56d8b1e..09247d9 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Utils.java +++ b/Ironhack-school/src/main/java/ironhack/com/Utils.java @@ -3,7 +3,8 @@ public class Utils { - public String generateSerialId () { + public static String generateSerialId () { + return UUID.randomUUID().toString(); } } From 51afe70631f2138227451de4e9db6ca637a59c47 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 13:09:13 +0100 Subject: [PATCH 06/81] add person constructor --- Ironhack-school/src/main/java/ironhack/com/Person.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/Person.java b/Ironhack-school/src/main/java/ironhack/com/Person.java index 52d65e9..afdb520 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Person.java +++ b/Ironhack-school/src/main/java/ironhack/com/Person.java @@ -7,4 +7,9 @@ public abstract class Person { private String id; private String name; + + public void person(String name){ + setName(name); + setId(Utils.generateSerialId()); + } } From 35ffc123271197c56856ff10840840324c9a5803 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 13:31:11 +0100 Subject: [PATCH 07/81] bug fix Person constructor and courses class --- .../src/main/java/ironhack/com/Course.java | 12 ++++++++---- .../src/main/java/ironhack/com/Person.java | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java index fa4596b..bd441e0 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Course.java +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -5,23 +5,27 @@ @Getter @Setter -public class Course { +public class Course extends Person { private String Id; private String name; private double price; private double money_earned; private Teacher teacher; - public void course(String name, double price){ + public Course(String name) { + super(name); + } + + public Course(String name, double price){ super(name); setPrice(price); } - public void course(String name, double price,Teacher teacher){ + public Course(String name, double price,Teacher teacher){ super(name); setPrice(price); setTeacher(teacher); } public void assign(String teacherId) { - setTeacher(); + //setTeacher(); } } diff --git a/Ironhack-school/src/main/java/ironhack/com/Person.java b/Ironhack-school/src/main/java/ironhack/com/Person.java index afdb520..54bda54 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Person.java +++ b/Ironhack-school/src/main/java/ironhack/com/Person.java @@ -8,8 +8,9 @@ public abstract class Person { private String id; private String name; - public void person(String name){ + public Person(String name){ setName(name); setId(Utils.generateSerialId()); } + } From 6d9fe7fb19e10775a2ad6fc2c3bb5d0c3541bf34 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 13:42:42 +0100 Subject: [PATCH 08/81] course is not a child of person --- .../src/main/java/ironhack/com/Course.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java index bd441e0..6f79a06 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Course.java +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -4,28 +4,33 @@ @Getter @Setter - -public class Course extends Person { +public class Course { private String Id; private String name; private double price; private double money_earned; private Teacher teacher; + public void setId(){ + setId(Utils.generateSerialId()); + } public Course(String name) { - super(name); + setId(); + setName(name); } public Course(String name, double price){ - super(name); + setId(); + setName(name); setPrice(price); } public Course(String name, double price,Teacher teacher){ - super(name); + setId(); + setName(name); setPrice(price); setTeacher(teacher); } - public void assign(String teacherId) { - //setTeacher(); + public void assign(Teacher teacher) { + setTeacher(teacher); } } From 24afc1deab758da8d2d162eca32fc7e5281995df Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Sat, 24 Feb 2024 13:47:58 +0100 Subject: [PATCH 09/81] constructor creation for student --- .../src/main/java/ironhack/com/Student.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/Student.java b/Ironhack-school/src/main/java/ironhack/com/Student.java index 7078b7c..750f0a0 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Student.java +++ b/Ironhack-school/src/main/java/ironhack/com/Student.java @@ -9,4 +9,17 @@ public class Student extends Person{ private String address; private String email; private List courseList; + + public Student(String name, String address, String email) { + super(name); + this.address = address; + this.email = email; + } + + public Student(String name, String address, String email, List courseList) { + super(name); + this.address = address; + this.email = email; + this.courseList = courseList; + } } From cc17609979bab23cc3f9ab3e37f189b9acbfb630 Mon Sep 17 00:00:00 2001 From: ivandavid858 Date: Sat, 24 Feb 2024 14:18:49 +0100 Subject: [PATCH 10/81] Create teacher constructor --- Ironhack-school/src/main/java/ironhack/com/Teacher.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 10f0b0a..580819e 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -4,6 +4,12 @@ @Getter @Setter -public class Teacher { +public class Teacher extends Person { + private double salary; + + public Teacher(String name, double salary) { + super(name); + this.salary = salary; + } } From 3cb392057b69e56074b0cdcd26e16731b8e5f1da Mon Sep 17 00:00:00 2001 From: ivandavid858 Date: Sat, 24 Feb 2024 14:22:32 +0100 Subject: [PATCH 11/81] Modify setSalary --- Ironhack-school/src/main/java/ironhack/com/Teacher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 580819e..54318de 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -10,6 +10,6 @@ public class Teacher extends Person { public Teacher(String name, double salary) { super(name); - this.salary = salary; + setSalary(salary); } } From 1bc2e6575749fdc617e911cb210589a6c5d4d0d9 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Sat, 24 Feb 2024 14:25:47 +0100 Subject: [PATCH 12/81] Addition of logic in lookup methods --- .../src/main/java/ironhack/com/School.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 6029563..bae0b06 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -1,6 +1,11 @@ package ironhack.com; +import lombok.Getter; +import lombok.Setter; import java.util.List; +import java.util.Objects; +@Getter +@Setter public class School { private List studentList; private List teacherList; @@ -11,14 +16,33 @@ private void showStudents() { } private Student lookupStudent(String studentId) { + for(Student student : studentList) { + if (Objects.equals(student.getId(), studentId)) { + return student; + } + } return null; } +// private Object lookupObject(String id, List objectList) { +// for(Object object : objectList) { +// if (Objects.equals(object.getId(), id)) { +// return object; +// } +// } +// return null; +// } + private void showCourses() { - // codigo + } private Course lookupCourse(String courseId) { + for(Course course : courseList) { + if (Objects.equals(course.getId(), courseId)) { + return course; + } + } return null; } @@ -27,6 +51,11 @@ private void showTeachers() { } private Teacher lookupTeacher(String teacherId) { + for(Teacher teacher : teacherList) { + if (Objects.equals(teacher.getId(), teacherId)) { + return teacher; + } + } return null; } From 24b441899b3081b00867efbf070b39dd99c0c100 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Sat, 24 Feb 2024 14:39:46 +0100 Subject: [PATCH 13/81] Addition of logic in show methods --- .../src/main/java/ironhack/com/Course.java | 8 ++++++++ .../src/main/java/ironhack/com/School.java | 13 +++++++++---- .../src/main/java/ironhack/com/Student.java | 8 ++++++++ .../src/main/java/ironhack/com/Teacher.java | 6 ++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java index 6f79a06..2c2ba9c 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Course.java +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -33,4 +33,12 @@ public Course(String name, double price,Teacher teacher){ public void assign(Teacher teacher) { setTeacher(teacher); } + + public void printInfo() { + System.out.println("Id: " + getId() + + ", Name: " + getName() + + ", Price: " + getPrice() + + ", Money Earned: " + getMoney_earned() + + ", Teacher: " + getTeacher().getName()); + } } diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index bae0b06..d0888e2 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -12,7 +12,9 @@ public class School { private List courseList; private void showStudents() { - // codigo + for (Student student : studentList) { + student.printInfo(); + } } private Student lookupStudent(String studentId) { @@ -34,7 +36,9 @@ private Student lookupStudent(String studentId) { // } private void showCourses() { - + for (Course course : courseList) { + course.printInfo(); + } } private Course lookupCourse(String courseId) { @@ -47,8 +51,9 @@ private Course lookupCourse(String courseId) { } private void showTeachers() { - // codigo - } + for (Teacher teacher : teacherList) { + teacher.printInfo(); + } } private Teacher lookupTeacher(String teacherId) { for(Teacher teacher : teacherList) { diff --git a/Ironhack-school/src/main/java/ironhack/com/Student.java b/Ironhack-school/src/main/java/ironhack/com/Student.java index 750f0a0..7e799a9 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Student.java +++ b/Ironhack-school/src/main/java/ironhack/com/Student.java @@ -22,4 +22,12 @@ public Student(String name, String address, String email, List courseLis this.email = email; this.courseList = courseList; } + + public void printInfo() { + System.out.println("Id: " + getId() + + ", Name: " + getName() + + ", Address: " + getAddress() + + ", Email: " + getEmail() + + ", Courses: " + getCourseList().toString()); + } } diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 54318de..7bcde46 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -12,4 +12,10 @@ public Teacher(String name, double salary) { super(name); setSalary(salary); } + + public void printInfo() { + System.out.println("Id: " + getId() + + ", Name: " + getName() + + ", Salary: " + getSalary()); + } } From 7d31b3109a4153417fd2738d284f94246ff75c07 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Sat, 24 Feb 2024 14:51:05 +0100 Subject: [PATCH 14/81] Addition of calculateProfit method --- .../src/main/java/ironhack/com/School.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index d0888e2..38fdb8b 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -11,13 +11,13 @@ public class School { private List teacherList; private List courseList; - private void showStudents() { + public void showStudents() { for (Student student : studentList) { student.printInfo(); } } - private Student lookupStudent(String studentId) { + public Student lookupStudent(String studentId) { for(Student student : studentList) { if (Objects.equals(student.getId(), studentId)) { return student; @@ -26,7 +26,7 @@ private Student lookupStudent(String studentId) { return null; } -// private Object lookupObject(String id, List objectList) { +// public Object lookupObject(String id, List objectList) { // for(Object object : objectList) { // if (Objects.equals(object.getId(), id)) { // return object; @@ -35,13 +35,13 @@ private Student lookupStudent(String studentId) { // return null; // } - private void showCourses() { + public void showCourses() { for (Course course : courseList) { course.printInfo(); } } - private Course lookupCourse(String courseId) { + public Course lookupCourse(String courseId) { for(Course course : courseList) { if (Objects.equals(course.getId(), courseId)) { return course; @@ -50,12 +50,12 @@ private Course lookupCourse(String courseId) { return null; } - private void showTeachers() { + public void showTeachers() { for (Teacher teacher : teacherList) { teacher.printInfo(); } } - private Teacher lookupTeacher(String teacherId) { + public Teacher lookupTeacher(String teacherId) { for(Teacher teacher : teacherList) { if (Objects.equals(teacher.getId(), teacherId)) { return teacher; @@ -64,5 +64,15 @@ private Teacher lookupTeacher(String teacherId) { return null; } - + public double calculateProfit() { + // TODO: exception handling + double profit = 0; + for (Course course : courseList) { + profit += course.getMoney_earned(); + } + for (Teacher teacher : teacherList) { + profit -= teacher.getSalary(); + } + return profit; + } } From bb5a33b337de7173b2835519ce4cc99eb67addd6 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Tue, 27 Feb 2024 13:41:23 +0100 Subject: [PATCH 15/81] change list to map --- .../src/main/java/ironhack/com/School.java | 86 +++++++++++-------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 38fdb8b..2f534b2 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -1,76 +1,88 @@ package ironhack.com; + import lombok.Getter; import lombok.Setter; + +import java.util.HashMap; import java.util.List; -import java.util.Objects; +import java.util.Map; @Getter @Setter public class School { - private List studentList; - private List teacherList; - private List courseList; + private String name; + private Map student_map = new HashMap<>(); + private Map teacher_map = new HashMap<>(); + private Map course_map = new HashMap<>(); + + public School(String name) { + this.name = name; + } public void showStudents() { - for (Student student : studentList) { + student_map.forEach((id, student) -> { student.printInfo(); - } + }); } public Student lookupStudent(String studentId) { - for(Student student : studentList) { - if (Objects.equals(student.getId(), studentId)) { - return student; - } + return student_map.get(studentId); + } + + public void setListToStudentMap(List students) { + Map students_map = new HashMap<>(); + + for (Student student : students) { + students_map.put(student.getId(), student); + } + setStudent_map(students_map); + } + + public void setListToCourseMap(List courses) { + Map courses_map = new HashMap<>(); + for (Course course : courses) { + courses_map.put(course.getId(), course); } - return null; + setCourse_map(courses_map); } -// public Object lookupObject(String id, List objectList) { -// for(Object object : objectList) { -// if (Objects.equals(object.getId(), id)) { -// return object; -// } -// } -// return null; -// } + public void setListToTeacherMap(List teachers) { + + Map teachers_map = new HashMap<>(); + for (Teacher teacher : teachers) { + teachers_map.put(teacher.getId(), teacher); + } + setTeacher_map(teachers_map); + } public void showCourses() { - for (Course course : courseList) { + course_map.forEach((id, course) -> { course.printInfo(); - } + }); } public Course lookupCourse(String courseId) { - for(Course course : courseList) { - if (Objects.equals(course.getId(), courseId)) { - return course; - } - } - return null; + return course_map.get(courseId); } public void showTeachers() { - for (Teacher teacher : teacherList) { + teacher_map.forEach((id, teacher) -> { teacher.printInfo(); - } } + }); + } public Teacher lookupTeacher(String teacherId) { - for(Teacher teacher : teacherList) { - if (Objects.equals(teacher.getId(), teacherId)) { - return teacher; - } - } - return null; + return teacher_map.get(teacherId); } public double calculateProfit() { // TODO: exception handling double profit = 0; - for (Course course : courseList) { + for (Course course : course_map.values()) { profit += course.getMoney_earned(); } - for (Teacher teacher : teacherList) { + ; + for (Teacher teacher : teacher_map.values()) { profit -= teacher.getSalary(); } return profit; From 0c879800f31097484b4f84bebcd726be00aeb6b7 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Tue, 27 Feb 2024 13:41:41 +0100 Subject: [PATCH 16/81] handling case is null --- Ironhack-school/src/main/java/ironhack/com/Course.java | 2 +- Ironhack-school/src/main/java/ironhack/com/Student.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java index 2c2ba9c..2252a0f 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Course.java +++ b/Ironhack-school/src/main/java/ironhack/com/Course.java @@ -39,6 +39,6 @@ public void printInfo() { + ", Name: " + getName() + ", Price: " + getPrice() + ", Money Earned: " + getMoney_earned() - + ", Teacher: " + getTeacher().getName()); + + ", Teacher: " +(getTeacher() != null ? getTeacher().getName() : "N/A")); } } diff --git a/Ironhack-school/src/main/java/ironhack/com/Student.java b/Ironhack-school/src/main/java/ironhack/com/Student.java index 7e799a9..f30093a 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Student.java +++ b/Ironhack-school/src/main/java/ironhack/com/Student.java @@ -5,7 +5,7 @@ @Getter @Setter -public class Student extends Person{ +public class Student extends Person { private String address; private String email; private List courseList; @@ -28,6 +28,6 @@ public void printInfo() { + ", Name: " + getName() + ", Address: " + getAddress() + ", Email: " + getEmail() - + ", Courses: " + getCourseList().toString()); + + ", Courses: " + (getCourseList() != null ? getCourseList().toString() : "N/A")); } -} +} \ No newline at end of file From 958363e33d271399fa9f1ac42dfc62a76cd5ed84 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Tue, 27 Feb 2024 13:42:33 +0100 Subject: [PATCH 17/81] create school from csv --- .../src/main/java/ironhack/com/App.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java index 30f12c6..2fc189a 100644 --- a/Ironhack-school/src/main/java/ironhack/com/App.java +++ b/Ironhack-school/src/main/java/ironhack/com/App.java @@ -1,9 +1,34 @@ package ironhack.com; -public class App +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static ironhack.com.ReadCsvInfo.readObjectInfo; +import static ironhack.com.ReadCsvInfo.readSchoolInfo; + +public class App { - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); + public static void main( String[] args ) throws FileNotFoundException { + String[] school_info = readSchoolInfo(); + School school = new School(school_info[0]); + + List teachers = readObjectInfo("src/files/Teachers.csv",1,RoleType.TEACHER); + List students = readObjectInfo("src/files/Students.csv",2,RoleType.STUDENT); + List courses = readObjectInfo("src/files/Courses.csv",2,RoleType.COURSE); + + school.setListToStudentMap(students); + school.setListToTeacherMap(teachers); + school.setListToCourseMap(courses); + + System.out.println("All Courses"); + school.showCourses(); + + System.out.println("All Teachers"); + school.showTeachers(); + + System.out.println("All Students"); + school.showStudents(); } } From fbdb33f02aa800be15e7eb0e3d866a463c86a666 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Tue, 27 Feb 2024 13:43:02 +0100 Subject: [PATCH 18/81] csv dummy info --- Ironhack-school/src/files/Courses.csv | 3 +++ Ironhack-school/src/files/School.csv | 2 ++ Ironhack-school/src/files/Students.csv | 3 +++ Ironhack-school/src/files/Teachers.csv | 2 ++ 4 files changed, 10 insertions(+) create mode 100644 Ironhack-school/src/files/Courses.csv create mode 100644 Ironhack-school/src/files/School.csv create mode 100644 Ironhack-school/src/files/Students.csv create mode 100644 Ironhack-school/src/files/Teachers.csv diff --git a/Ironhack-school/src/files/Courses.csv b/Ironhack-school/src/files/Courses.csv new file mode 100644 index 0000000..4ca2d30 --- /dev/null +++ b/Ironhack-school/src/files/Courses.csv @@ -0,0 +1,3 @@ +name,price,money_earned +web_development,3500,50000 +java_backend,7500,150000 diff --git a/Ironhack-school/src/files/School.csv b/Ironhack-school/src/files/School.csv new file mode 100644 index 0000000..eb042ab --- /dev/null +++ b/Ironhack-school/src/files/School.csv @@ -0,0 +1,2 @@ +name,teacher_number,courses_number,student_number +iron_copy,1,2,2 \ No newline at end of file diff --git a/Ironhack-school/src/files/Students.csv b/Ironhack-school/src/files/Students.csv new file mode 100644 index 0000000..430c361 --- /dev/null +++ b/Ironhack-school/src/files/Students.csv @@ -0,0 +1,3 @@ +name,address,email,courseList +estefania,barcelona,estefania@ironhack.com,[] +ivan,barcelona,ivan@ironhack.com,[], \ No newline at end of file diff --git a/Ironhack-school/src/files/Teachers.csv b/Ironhack-school/src/files/Teachers.csv new file mode 100644 index 0000000..ca1f930 --- /dev/null +++ b/Ironhack-school/src/files/Teachers.csv @@ -0,0 +1,2 @@ +name,salary +antonio,40000 \ No newline at end of file From 55524a0e844ddedc60608b4d7ba8b37e13e72a50 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Tue, 27 Feb 2024 13:43:45 +0100 Subject: [PATCH 19/81] read info from csv --- .../main/java/ironhack/com/ReadCsvInfo.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java diff --git a/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java b/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java new file mode 100644 index 0000000..7f221e7 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java @@ -0,0 +1,51 @@ +package ironhack.com; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.*; + +public class ReadCsvInfo { + //TODO handling possible exceptions + public static String[] readSchoolInfo() throws FileNotFoundException { + String SCHOOL_PATH = "src/files/School.csv"; + File file_school = new File(SCHOOL_PATH); + Scanner school_scanner =new Scanner(file_school); + + school_scanner.nextLine(); + String[] school_vector = school_scanner.nextLine().split(","); + return school_vector; + } + public static List readObjectInfo(String path, int rowsToRead, RoleType type) throws FileNotFoundException { + File file = new File(path); + Scanner sc = new Scanner(file); + List objectList = new ArrayList<>(); + + sc.nextLine(); + for (int i = 1; i <= rowsToRead; i++) { + String[] properties = sc.nextLine().split(","); + ObjectType newObj = createInstance(type, properties); + objectList.add(newObj); + } + return objectList; + } + + private static ObjectType createInstance(RoleType type, String[] properties) { + switch (type) { + case TEACHER: + @SuppressWarnings("unchecked") + ObjectType teacher = (ObjectType) new Teacher(properties[0], Double.parseDouble(properties[1])); + return teacher; + case STUDENT: + @SuppressWarnings("unchecked") + ObjectType student = (ObjectType) new Student(properties[0], properties[1], properties[2]); + return student; + case COURSE: + @SuppressWarnings("unchecked") + ObjectType course = (ObjectType) new Course(properties[0], Double.parseDouble(properties[1])); + return course; + default: + throw new IllegalArgumentException("Invalid RoleType"); + } + } + +} From c06e982bd47052748fa57d2ec77326ae75a47030 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Tue, 27 Feb 2024 13:43:55 +0100 Subject: [PATCH 20/81] Enum form type of entity --- Ironhack-school/src/main/java/ironhack/com/RoleType.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Ironhack-school/src/main/java/ironhack/com/RoleType.java diff --git a/Ironhack-school/src/main/java/ironhack/com/RoleType.java b/Ironhack-school/src/main/java/ironhack/com/RoleType.java new file mode 100644 index 0000000..2069c23 --- /dev/null +++ b/Ironhack-school/src/main/java/ironhack/com/RoleType.java @@ -0,0 +1,7 @@ +package ironhack.com; + +public enum RoleType { + TEACHER, + STUDENT, + COURSE +} From 73179b8d657008f419e40216a9c6084a40a09d83 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Thu, 29 Feb 2024 21:03:48 +0100 Subject: [PATCH 21/81] Added salary validation --- Ironhack-school/src/main/java/ironhack/com/Teacher.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 7bcde46..751db62 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -13,6 +13,14 @@ public Teacher(String name, double salary) { setSalary(salary); } + public void setSalary(double salary) { + if (Double.isNaN(salary)) { + System.err.println("The input for salary must be a number"); + } else { + this.salary = salary; + } + } + public void printInfo() { System.out.println("Id: " + getId() + ", Name: " + getName() From c3a1b50287b5d97ad658d3acec4fbbff9e7439c7 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail <115991775+katalinjordansgmail@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:11:53 +0100 Subject: [PATCH 22/81] Revert "Added salary validation" --- Ironhack-school/src/main/java/ironhack/com/Teacher.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 751db62..7bcde46 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -13,14 +13,6 @@ public Teacher(String name, double salary) { setSalary(salary); } - public void setSalary(double salary) { - if (Double.isNaN(salary)) { - System.err.println("The input for salary must be a number"); - } else { - this.salary = salary; - } - } - public void printInfo() { System.out.println("Id: " + getId() + ", Name: " + getName() From 53e4e5b077eec0f0521610025d424ed9522808fa Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Thu, 29 Feb 2024 21:21:28 +0100 Subject: [PATCH 23/81] Added salary validation --- Ironhack-school/src/main/java/ironhack/com/Teacher.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 751db62..f407362 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -26,4 +26,5 @@ public void printInfo() { + ", Name: " + getName() + ", Salary: " + getSalary()); } + //test } From 9ac6bd9f0eca37630d6c64d9f8fe4bc3c06b221c Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Thu, 29 Feb 2024 21:21:42 +0100 Subject: [PATCH 24/81] Added salary validation --- Ironhack-school/src/main/java/ironhack/com/Teacher.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index f407362..751db62 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -26,5 +26,4 @@ public void printInfo() { + ", Name: " + getName() + ", Salary: " + getSalary()); } - //test } From 9a9ccc50d584ca42594367a650f9bd645e402ee5 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Thu, 29 Feb 2024 21:26:53 +0100 Subject: [PATCH 25/81] added salary validation --- .../src/main/java/ironhack/com/Teacher.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java index 7bcde46..c8e369b 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Teacher.java +++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java @@ -13,9 +13,17 @@ public Teacher(String name, double salary) { setSalary(salary); } + public void setSalary(double salary) { + if (Double.isNaN(salary)) { + System.err.println("The input for salary must be a number"); + } else { + this.salary = salary; + } + } + public void printInfo() { System.out.println("Id: " + getId() + ", Name: " + getName() + ", Salary: " + getSalary()); } -} +} \ No newline at end of file From f6d9a960992c97090eebf95f39bda2ccb8d38a0e Mon Sep 17 00:00:00 2001 From: ivandavid858 Date: Thu, 29 Feb 2024 21:31:54 +0100 Subject: [PATCH 26/81] Create enroll method to enroll a student to a course --- .../src/main/java/ironhack/com/App.java | 4 +++ .../src/main/java/ironhack/com/School.java | 25 +++++++++++++++++++ .../src/main/java/ironhack/com/Student.java | 7 ++++++ 3 files changed, 36 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java index 2fc189a..518c5d3 100644 --- a/Ironhack-school/src/main/java/ironhack/com/App.java +++ b/Ironhack-school/src/main/java/ironhack/com/App.java @@ -30,5 +30,9 @@ public static void main( String[] args ) throws FileNotFoundException { System.out.println("All Students"); school.showStudents(); + + System.out.println("\nEnroll"); + school.enroll(students.get(0).getId(), courses.get(0).getId()); + } } diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 2f534b2..2f17865 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -87,4 +87,29 @@ public double calculateProfit() { } return profit; } + + public void enroll(String studentId, String courseId) { + Student student = findStudentById(studentId); + Course course = findCourseById(courseId); + + if (student == null) { + throw new IllegalArgumentException("Student not found."); + } + + if (course == null) { + throw new IllegalArgumentException("Course not found."); + } + + course.setMoney_earned(course.getPrice()); + student.enrollInCourse(course); + + } + + private Student findStudentById(String studentId) { + return student_map.get(studentId); + } + + private Course findCourseById(String courseId) { + return course_map.get(courseId); + } } diff --git a/Ironhack-school/src/main/java/ironhack/com/Student.java b/Ironhack-school/src/main/java/ironhack/com/Student.java index f30093a..1d54007 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Student.java +++ b/Ironhack-school/src/main/java/ironhack/com/Student.java @@ -1,6 +1,8 @@ package ironhack.com; import lombok.Getter; import lombok.Setter; + +import java.util.ArrayList; import java.util.List; @Getter @@ -14,6 +16,7 @@ public Student(String name, String address, String email) { super(name); this.address = address; this.email = email; + courseList = new ArrayList<>(); } public Student(String name, String address, String email, List courseList) { @@ -30,4 +33,8 @@ public void printInfo() { + ", Email: " + getEmail() + ", Courses: " + (getCourseList() != null ? getCourseList().toString() : "N/A")); } + + public void enrollInCourse(Course course) { + this.courseList.add(course); + } } \ No newline at end of file From 588ac886730a4b63059d342203fa15c226da2d81 Mon Sep 17 00:00:00 2001 From: katalinjordansgmail Date: Thu, 29 Feb 2024 21:56:01 +0100 Subject: [PATCH 27/81] Updated assignTeacherToCourse method --- .../src/main/java/ironhack/com/School.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 2f17865..6c2d89c 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -102,7 +102,23 @@ public void enroll(String studentId, String courseId) { course.setMoney_earned(course.getPrice()); student.enrollInCourse(course); + } + + public void assignTeacherToCourse(String teacherId, String courseId) { + course_map.get(courseId).setTeacher(teacher_map.get(teacherId)); + + Teacher teacher = findTeacherById(teacherId); + Course course = findCourseById(courseId); + if (teacher == null) { + throw new IllegalArgumentException("Teacher not found."); + } + + if (course == null) { + throw new IllegalArgumentException("Course not found."); + } + + course.assign(teacher); } private Student findStudentById(String studentId) { @@ -112,4 +128,8 @@ private Student findStudentById(String studentId) { private Course findCourseById(String courseId) { return course_map.get(courseId); } -} + + private Teacher findTeacherById(String teacherId) { + return teacher_map.get(teacherId); + } +} \ No newline at end of file From b29e145ecff6e0a2d3b5c72cf242d52c01560b61 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Thu, 29 Feb 2024 22:05:23 +0100 Subject: [PATCH 28/81] move create school to ReadCsvInfo --- .../main/java/ironhack/com/ReadCsvInfo.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java b/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java index 7f221e7..ce88397 100644 --- a/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java +++ b/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java @@ -48,4 +48,26 @@ private static ObjectType createInstance(RoleType type, String[] pr } } + public static void school_creation_csv() throws FileNotFoundException { + String[] school_info = readSchoolInfo(); + School school = new School(school_info[0]); + + List teachers = readObjectInfo("src/files/Teachers.csv",1,RoleType.TEACHER); + List students = readObjectInfo("src/files/Students.csv",2,RoleType.STUDENT); + List courses = readObjectInfo("src/files/Courses.csv",2,RoleType.COURSE); + + school.setListToStudentMap(students); + school.setListToTeacherMap(teachers); + school.setListToCourseMap(courses); + + System.out.println("All Courses"); + school.showCourses(); + + System.out.println("All Teachers"); + school.showTeachers(); + + System.out.println("All Students"); + school.showStudents(); + } + } From 3a39d79ee5ab4902cfa32779a87c7fb2cd132642 Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Thu, 29 Feb 2024 22:05:37 +0100 Subject: [PATCH 29/81] validate_number_of method --- .../src/main/java/ironhack/com/Utils.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/Utils.java b/Ironhack-school/src/main/java/ironhack/com/Utils.java index 09247d9..8bfa820 100644 --- a/Ironhack-school/src/main/java/ironhack/com/Utils.java +++ b/Ironhack-school/src/main/java/ironhack/com/Utils.java @@ -1,4 +1,5 @@ package ironhack.com; +import java.util.Scanner; import java.util.UUID; public class Utils { @@ -7,4 +8,20 @@ public static String generateSerialId () { return UUID.randomUUID().toString(); } + + public static int validate_number_of(Scanner scanner){ + boolean is_finish= false; + + do{ + String number_string=scanner.nextLine(); + try{ + int number= Integer.parseInt(number_string); + return number; + } catch (NumberFormatException e){ + System.out.println("Enter a valid number"); + } + is_finish=true; + }while(is_finish); + return 0; + } } From 2f2f7e3365ecb2e7427f0bea8da8f8790363f44a Mon Sep 17 00:00:00 2001 From: Estefania Amundaray Date: Thu, 29 Feb 2024 22:05:56 +0100 Subject: [PATCH 30/81] menu creation --- .../src/main/java/ironhack/com/App.java | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java index 2fc189a..92f7b81 100644 --- a/Ironhack-school/src/main/java/ironhack/com/App.java +++ b/Ironhack-school/src/main/java/ironhack/com/App.java @@ -1,34 +1,63 @@ package ironhack.com; import java.io.FileNotFoundException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static ironhack.com.ReadCsvInfo.readObjectInfo; import static ironhack.com.ReadCsvInfo.readSchoolInfo; +import static ironhack.com.Utils.validate_number_of; public class App { - public static void main( String[] args ) throws FileNotFoundException { - String[] school_info = readSchoolInfo(); - School school = new School(school_info[0]); + public static void main( String[] args ) { + Scanner scanner = new Scanner(System.in); - List teachers = readObjectInfo("src/files/Teachers.csv",1,RoleType.TEACHER); - List students = readObjectInfo("src/files/Students.csv",2,RoleType.STUDENT); - List courses = readObjectInfo("src/files/Courses.csv",2,RoleType.COURSE); + boolean is_finish= false; + do{ - school.setListToStudentMap(students); - school.setListToTeacherMap(teachers); - school.setListToCourseMap(courses); - System.out.println("All Courses"); - school.showCourses(); + System.out.println("*******School Management System******"); - System.out.println("All Teachers"); - school.showTeachers(); + System.out.println( "Let's create an School"); + System.out.println( "Enter a Name:"); + scanner.nextLine(); - System.out.println("All Students"); - school.showStudents(); + System.out.println("how many teachers should be created?"); + int teacher_number = validate_number_of(scanner); + System.out.println(teacher_number); + create_teachers(scanner,teacher_number); + + System.out.println("how many courses should be created?"); + int courses_number = validate_number_of(scanner); + System.out.println(courses_number); + + System.out.println("how many students should be created?"); + int students_number = validate_number_of(scanner); + //TODO validate more than 0 + System.out.println(students_number); + + + //more than 0 and + is_finish=true; + + }while(!is_finish); } + + public static void create_teachers(Scanner scanner, int teacher_number){ + + List teachers_list= new ArrayList<>(); + for (int i=1; i Date: Tue, 5 Mar 2024 17:33:21 +0100 Subject: [PATCH 31/81] Create method to show students enrolled to a course --- .../src/main/java/ironhack/com/App.java | 3 +++ .../src/main/java/ironhack/com/School.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java index 518c5d3..091e85e 100644 --- a/Ironhack-school/src/main/java/ironhack/com/App.java +++ b/Ironhack-school/src/main/java/ironhack/com/App.java @@ -34,5 +34,8 @@ public static void main( String[] args ) throws FileNotFoundException { System.out.println("\nEnroll"); school.enroll(students.get(0).getId(), courses.get(0).getId()); + System.out.println("\nShow students by course"); + school.showStudentsByCourseId(courses.get(0).getId()); + } } diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 6c2d89c..d2ff8fb 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -3,6 +3,7 @@ import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -132,4 +133,24 @@ private Course findCourseById(String courseId) { private Teacher findTeacherById(String teacherId) { return teacher_map.get(teacherId); } + + public void showStudentsByCourseId(String courseId) { + Course course = findCourseById(courseId); + + if (course == null) { + throw new IllegalArgumentException("Course not found"); + } + + List enrolledStudents = new ArrayList<>(); + for (Student st : student_map.values()) { + if (st.getCourseList().contains(course)) { + enrolledStudents.add(st); + } + } + + for (Student st : enrolledStudents) { + st.printInfo(); + } + } + } \ No newline at end of file From 8a978d5c28e2fb864828718c58d0c5844c67edee Mon Sep 17 00:00:00 2001 From: ivandavid858 Date: Tue, 5 Mar 2024 18:52:40 +0100 Subject: [PATCH 32/81] Fix setMoney setMoney_earnet method --- Ironhack-school/src/main/java/ironhack/com/School.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 2f17865..c073b20 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -100,8 +100,8 @@ public void enroll(String studentId, String courseId) { throw new IllegalArgumentException("Course not found."); } - course.setMoney_earned(course.getPrice()); student.enrollInCourse(course); + course.setMoney_earned(course.getMoney_earned() + course.getPrice()); } From 28646b58ca7c26c5251d9008bd3d1a949a692810 Mon Sep 17 00:00:00 2001 From: ivandavid858 Date: Tue, 5 Mar 2024 21:59:07 +0100 Subject: [PATCH 33/81] Create method showMoneySpentByStudent --- .../src/main/java/ironhack/com/School.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java index 6c2d89c..80a076d 100644 --- a/Ironhack-school/src/main/java/ironhack/com/School.java +++ b/Ironhack-school/src/main/java/ironhack/com/School.java @@ -132,4 +132,22 @@ private Course findCourseById(String courseId) { private Teacher findTeacherById(String teacherId) { return teacher_map.get(teacherId); } + + public void showMoneySpentByStudent(String studentId) { + double totalMoneySpent = 0.0; + + Student student = student_map.get(studentId); + + if (student == null) { + throw new IllegalArgumentException("Student not found"); + } + + List courses = student.getCourseList(); + for (Course course : courses) { + totalMoneySpent += course.getPrice(); + } + + System.out.println(totalMoneySpent); + } + } \ No newline at end of file From 282d49f4cec4c100fe18e680505be41b0fff31c6 Mon Sep 17 00:00:00 2001 From: lausaru Date: Sat, 9 Mar 2024 14:46:26 +0100 Subject: [PATCH 34/81] updated lookup methods to print info --- Ironhack-school/.idea/workspace.xml | 26 +++++++------------ .../src/main/java/ironhack/com/App.java | 4 +++ .../src/main/java/ironhack/com/School.java | 12 ++++----- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Ironhack-school/.idea/workspace.xml b/Ironhack-school/.idea/workspace.xml index 16d51eb..17c62e9 100644 --- a/Ironhack-school/.idea/workspace.xml +++ b/Ironhack-school/.idea/workspace.xml @@ -5,16 +5,8 @@ - - - - - - - - - - + +