diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..cedb1e0 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..21cfa76 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..0c3156a --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/homework-java-ironschool.iml b/.idea/homework-java-ironschool.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/homework-java-ironschool.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7255851 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7d98804 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ironschool/pom.xml b/ironschool/pom.xml new file mode 100644 index 0000000..738afa8 --- /dev/null +++ b/ironschool/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + package1 + ironschool + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.junit.jupiter + junit-jupiter-api + 5.11.0-M2 + test + + + + \ No newline at end of file diff --git a/ironschool/src/main/java/package1/Course.java b/ironschool/src/main/java/package1/Course.java new file mode 100644 index 0000000..dac2c56 --- /dev/null +++ b/ironschool/src/main/java/package1/Course.java @@ -0,0 +1,71 @@ +package package1; + +import java.util.UUID; + +public class Course { + private String courseId = UUID.randomUUID().toString().substring(0, 6); + private String name; + private double price; + private double money_earned; + private Teacher teacher; + + public Course(String name, double price) { + this.name = name; + this.price = price; + } + + public Course() { + } + + public String getCourseId() { + return courseId; + } + + public void setCourseId(String courseId) { + this.courseId = courseId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public double getMoney_earned() { + return money_earned; + } + + public void setMoney_earned(double money_earned) { + this.money_earned = money_earned; + } + + public Teacher getTeacher() { + return teacher; + } + + public void setTeacher(Teacher teacher) { + this.teacher = teacher; + } + + @Override + public String toString() { + return "Course{" + + "courseId='" + courseId + '\'' + + ", name='" + name + '\'' + + ", price=" + price + + ", money_earned=" + money_earned + + ", teacher=" + teacher + + '}'; + } + +} \ No newline at end of file diff --git a/ironschool/src/main/java/package1/ICommands.java b/ironschool/src/main/java/package1/ICommands.java new file mode 100644 index 0000000..db0447c --- /dev/null +++ b/ironschool/src/main/java/package1/ICommands.java @@ -0,0 +1,15 @@ +package package1; + +public interface ICommands { + + void enroll(String studentName, String courseName); + void assign(String teacherName, String courseName); + void showCourses(); + void lookUpCourse(String courseName); + void showStudents(); + void lookUpStudent(String studentName); + void showTeachers(); + void lookUpTeacher(String teacherName); + void showProfit(); + +} diff --git a/ironschool/src/main/java/package1/Main.java b/ironschool/src/main/java/package1/Main.java new file mode 100644 index 0000000..30da928 --- /dev/null +++ b/ironschool/src/main/java/package1/Main.java @@ -0,0 +1,249 @@ +package package1; + +import java.util.*; + +public class Main implements ICommands { + + private static Map teachersList = new HashMap<>(); + private static Map coursesList = new HashMap<>(); + private static Map studentsList = new HashMap<>(); + + public static void main(String[] args) { + Main main = new Main(); + Scanner scannerIn = new Scanner(System.in); + + System.out.println("Please enter name to create a School"); + String schoolName = scannerIn.nextLine(); + System.out.println("How many teachers?"); + int numberOfTeachers = scannerIn.nextInt(); + scannerIn.nextLine(); + + for (int i = 0; i < numberOfTeachers; i++) { + System.out.println("Enter teacher" + (i + 1) + " name"); + String teacherName = scannerIn.nextLine(); + System.out.println("Enter " + teacherName + "'s salary"); + double teacherSalary = scannerIn.nextDouble(); + scannerIn.nextLine(); + + Teacher teacher = new Teacher(teacherName, teacherSalary); + teachersList.put(teacher.getName(), teacher); + } + System.out.println(teachersList); + + System.out.println("Enter the amount of courses"); + int numberOfCourses = scannerIn.nextInt(); + scannerIn.nextLine(); + + for (int i = 0; i < numberOfCourses; i++) { + System.out.println("Enter course" + (i + 1) + " name"); + String courseName = scannerIn.nextLine().trim().toLowerCase(); + System.out.println("Enter course price"); + double coursePrice = scannerIn.nextDouble(); + scannerIn.nextLine(); + + Course course = new Course(courseName, coursePrice); + coursesList.put(course.getName(), course); + } + + System.out.println(coursesList); + + System.out.println("Enter how many students"); + int numberOfStudents = scannerIn.nextInt(); + scannerIn.nextLine(); + + for (int i = 0; i < numberOfStudents; i++) { + System.out.println("Enter student's name"); + String name = scannerIn.nextLine(); + System.out.println("Enter student's address"); + String address = scannerIn.nextLine(); + System.out.println("Enter student's email"); + String email = scannerIn.nextLine(); + + Student student = new Student(name, address, email); + studentsList.put(student.getName(), student); + } + + System.out.println(studentsList); + + while (true) { + System.out.println(""" + Enter a command: + 1) ENROLL a student to a course + 2) ASSIGN a teacher to a course + 3) SHOW COURSES + 4) LOOKUP COURSE + 5) SHOW STUDENTS + 6) LOOKUP STUDENT + 7) SHOW TEACHERS + 8) LOOKUP TEACHER + 9) SHOW PROFIT + 10) EXIT + """); + + do{ + //this we did in class + scannerIn = new Scanner(System.in); + System.out.print("Enter a command: "); + } + while(!scannerIn.hasNextInt()); + + int option = scannerIn.nextInt(); + scannerIn.nextLine(); + String name; + String course; + + switch (option) { + case 1: + System.out.println("Enter student name:"); + name = scannerIn.nextLine(); + System.out.println("Enter course name:"); + course = scannerIn.nextLine(); + main.enroll(name, course); + break; + case 2: + System.out.println("Enter teacher name:"); + name = scannerIn.nextLine(); + System.out.println("Enter course name:"); + course = scannerIn.nextLine(); + main.assign(name, course); + break; + case 3: + main.showCourses(); + break; + case 4: + System.out.println("Enter course name:"); + course = scannerIn.nextLine(); + try{ + main.lookUpCourse(course); + } catch (InputMismatchException e){ + System.out.println("Name is not properly formatted: "+ course); + } + + break; + case 5: + main.showStudents(); + break; + case 6: + System.out.println("Enter student name:"); + name = scannerIn.nextLine(); + main.lookUpStudent(name); + break; + case 7: + main.showTeachers(); + break; + case 8: + System.out.println("Enter teacher name:"); + name = scannerIn.nextLine(); + main.lookUpTeacher(name); + break; + case 9: + main.showProfit(); + break; + case 10: + System.out.println("Exiting the program."); + scannerIn.close(); + return; + default: + System.out.println("Invalid command."); + } + } + } + + @Override + public void enroll(String studentName, String courseName) { + Student student = studentsList.get(studentName); + Course course = coursesList.get(courseName.toLowerCase().trim()); + if (student != null && course != null) { + student.setCourse(course); + course.setMoney_earned(course.getMoney_earned() + course.getPrice()); + System.out.println("Student " + student.getName() + " enrolled in course " + course.getName()); + + } else { + System.out.println("Invalid student or course name"); + } + } + + + @Override + public void assign(String teacherName, String courseName) { + Teacher teacher = teachersList.get(teacherName); + Course course = coursesList.get(courseName); + if (teacher != null && course != null) { + course.setTeacher(teacher); + System.out.println("Teacher " + teacher.getName() + " assigned to course " + course.getName()); + } else { + System.out.println("Invalid teacher or course name"); + } + } + + @Override + public void showCourses() { + System.out.println("These are the Courses:"); + for (Course course : coursesList.values()) { + System.out.println(course); + } + } + + @Override + public void lookUpCourse(String courseName) { + String courseN = courseName.trim().toLowerCase(); + Course course = coursesList.get(courseN); + if (course != null) { + System.out.println("This is the course: "+course); + } else { + System.out.println("Course not found"); + } + } + + @Override + public void showStudents() { + System.out.println("The students are: "); + for (Student student : studentsList.values()) { + System.out.println(student); + } + } + + @Override + public void lookUpStudent(String studentName) { + Student student = studentsList.get(studentName); + if (student != null) { + System.out.println(student); + } else { + System.out.println("Student not found"); + } + } + + @Override + public void showTeachers() { + System.out.println("Teachers:"); + for (Teacher teacher : teachersList.values()) { + System.out.println(teacher); + } + } + + @Override + public void lookUpTeacher(String teacherName) { + Teacher teacher = teachersList.get(teacherName); + if (teacher != null) { + System.out.println(teacher); + } else { + System.out.println("Teacher not found"); + } + } + + @Override + public void showProfit() { + double totalEarnings = 0; + for (Course course : coursesList.values()) { + totalEarnings += course.getMoney_earned(); + } + + double totalSalaries = 0; + for (Teacher teacher : teachersList.values()) { + totalSalaries += teacher.getSalary(); + } + + double profit = totalEarnings - totalSalaries; + System.out.println("Total profit: " + profit); + } +} \ No newline at end of file diff --git a/ironschool/src/main/java/package1/Student.java b/ironschool/src/main/java/package1/Student.java new file mode 100644 index 0000000..9dfb5ba --- /dev/null +++ b/ironschool/src/main/java/package1/Student.java @@ -0,0 +1,71 @@ +package package1; + +import java.util.UUID; + +public class Student { + private String studentId = UUID.randomUUID().toString().substring(0, 6); + private String name; + private String address; + private String email; + private Course course; + + public Student(String name, String address, String email) { + this.name = name; + this.address = address; + this.email = email; + } + + public Student() { + } + + public String getStudentId() { + return studentId; + } + + public void setStudentId(String studentId) { + this.studentId = studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Course getCourse() { + return course; + } + + public void setCourse(Course course) { + this.course = course; + } + + @Override + public String toString() { + return "Student{" + + "studentId='" + studentId + '\'' + + ", name='" + name + '\'' + + ", address='" + address + '\'' + + ", email='" + email + '\'' + + ", course=" + course + + '}'; + } +} \ No newline at end of file diff --git a/ironschool/src/main/java/package1/Teacher.java b/ironschool/src/main/java/package1/Teacher.java new file mode 100644 index 0000000..ac4cc6d --- /dev/null +++ b/ironschool/src/main/java/package1/Teacher.java @@ -0,0 +1,50 @@ +package package1; + +import java.util.UUID; + +public class Teacher { + private String teacherId = UUID.randomUUID().toString().substring(0, 6); //auto generated + private String name; + private double salary; + + public Teacher() { + } + + public Teacher(String name, double salary) { + this.name = name; + this.salary = salary; + } + + public String getTeacherId() { + return teacherId; + } + + public void setTeacherId(String teacherId) { + this.teacherId = teacherId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getSalary() { + return salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + @Override + public String toString() { + return "Teacher{" + + "teacherId='" + teacherId + '\'' + + ", name='" + name + '\'' + + ", salary=" + salary + + '}'; + } +} \ No newline at end of file diff --git a/ironschool/src/test/java/package1/MainTest.java b/ironschool/src/test/java/package1/MainTest.java new file mode 100644 index 0000000..437ab85 --- /dev/null +++ b/ironschool/src/test/java/package1/MainTest.java @@ -0,0 +1,37 @@ +package package1; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; +class MainTest { + + static Course course1; + static Teacher teacher1; + static Student student1; + + @BeforeAll + static void beforeAll() { + course1 = new Course("Math", 300); + teacher1 = new Teacher("Gabriel", 1000); + student1 = new Student("luie", "3476 Wonderland St.", "luie@example.com"); + } + + @Test + void main() { + + + System.out.println(course1.getCourseId().getClass()); + + System.out.println(teacher1); + student1.setCourse(course1); + System.out.println("This is the student with course: "+student1); + System.out.println(student1.getCourse()); + + } +} \ No newline at end of file diff --git a/ironschool/target/classes/package1/Course.class b/ironschool/target/classes/package1/Course.class new file mode 100644 index 0000000..7fd5397 Binary files /dev/null and b/ironschool/target/classes/package1/Course.class differ diff --git a/ironschool/target/classes/package1/ICommands.class b/ironschool/target/classes/package1/ICommands.class new file mode 100644 index 0000000..e172e8a Binary files /dev/null and b/ironschool/target/classes/package1/ICommands.class differ diff --git a/ironschool/target/classes/package1/Main.class b/ironschool/target/classes/package1/Main.class new file mode 100644 index 0000000..e1365d3 Binary files /dev/null and b/ironschool/target/classes/package1/Main.class differ diff --git a/ironschool/target/classes/package1/Student.class b/ironschool/target/classes/package1/Student.class new file mode 100644 index 0000000..24e295e Binary files /dev/null and b/ironschool/target/classes/package1/Student.class differ diff --git a/ironschool/target/classes/package1/Teacher.class b/ironschool/target/classes/package1/Teacher.class new file mode 100644 index 0000000..18e799b Binary files /dev/null and b/ironschool/target/classes/package1/Teacher.class differ diff --git a/ironschool/target/test-classes/package1/MainTest.class b/ironschool/target/test-classes/package1/MainTest.class new file mode 100644 index 0000000..ddd9be1 Binary files /dev/null and b/ironschool/target/test-classes/package1/MainTest.class differ