From cdd9cf296fe07bedf31652f582a92d9dd1fab14c Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Sun, 5 May 2019 21:08:43 -0700 Subject: [PATCH] resubmission of meme4 --- 338/homework4/App.java | 84 ++++++++++ 338/homework4/Course.java | 32 ++++ 338/homework4/Enrolled.java | 13 ++ 338/homework4/Instructor.java | 22 +++ 338/homework4/School.java | 300 ++++++++++++++++++++++++++++++++++ 338/homework4/Student.java | 37 +++++ 338/homework4/Test.java | 56 +++++++ 338/homework4/data1.txt | 13 ++ 338/homework4/data2.txt | 10 ++ 338/homework4/makefile | 8 + 10 files changed, 575 insertions(+) create mode 100644 338/homework4/App.java create mode 100644 338/homework4/Course.java create mode 100644 338/homework4/Enrolled.java create mode 100644 338/homework4/Instructor.java create mode 100644 338/homework4/School.java create mode 100644 338/homework4/Student.java create mode 100644 338/homework4/Test.java create mode 100644 338/homework4/data1.txt create mode 100644 338/homework4/data2.txt create mode 100644 338/homework4/makefile diff --git a/338/homework4/App.java b/338/homework4/App.java new file mode 100644 index 0000000..2f211bd --- /dev/null +++ b/338/homework4/App.java @@ -0,0 +1,84 @@ +/* +Author: Alejandro Santillana +Description: Builds a basic school data tracker + keeps track of students and what course they are enrolled in as well as what courses + are offered by the school. + Course information is also available + Input is read from file +*/ +public class App { + public static void main(String[] args) { + String dataFile1 = "data1.txt"; + String dataFile2 = "data2.txt"; + + // course reference for demo purposes + Course course1; + Student student1; + + // first we'll read in some data + System.out.println("===== Read Data 1 ====="); + School SCD = new School("CSUMB"); + // get all basic info about the SCD + SCD.readData(dataFile1); + + System.out.println("\n===== School Info 1 ====="); + SCD.schoolInfo(); + + // round 2 of adding info to the SCD + System.out.println("\n===== Read Data 2 ====="); + SCD.readData(dataFile2); + + System.out.println("\n===== School Info 2 ====="); + SCD.schoolInfo(); + + // we'll now add some new instructors + SCD.addInstructor(700, "E. Tao", "tao@csumb.edu", "777-777-1234"); + SCD.addCourse(300, "CST300 – ProSem", 700, "BIT110"); + SCD.addCourse(231, "CST231 – Intro C++", 100, "BIT104"); + + // examples of bad courses to add + System.out.println("\n===== Failed Course Addition ====="); + SCD.addCourse(306, "CST306 – GUI Dev", 250, "BIT120"); + SCD.addCourse(499, "CST499 – iOS Dev", 150, "BIT104"); + + System.out.println("\n===== Detailed Course Info ====="); + SCD.courseInfo(306); + + // updateing a courses location + course1 = SCD.getCourse(205); + course1.updateLocation("Library 104"); + + // checking some courses' information + System.out.println("\n===== Detailed Course Info 2 ====="); + SCD.courseInfo(205); + + System.out.println("\n===== Detailed Course Info 3 ====="); + SCD.courseInfo(); + SCD.deleteCourse(231); + SCD.deleteCourse(336); + SCD.deleteCourse(338); + + System.out.println("\n===== Detailed Course Info 4 ====="); + SCD.courseInfo(); + + // adding a student (valid this time) + SCD.addStudent(5555, "Chris Watson", 205, 85.50f, "B"); + System.out.println("\n===== Detailed Course Info 5 ====="); + SCD.courseInfo(205); + student1 = SCD.getStudentInfo(7777); + + // student info + System.out.println("\n===== Detailed Student Info ====="); + System.out.println(student1); + + System.out.println("\n===== Detailed Student Info 2 ====="); + System.out.println(SCD.getStudentInfo(7777)); + SCD.graduateStudent(5555); + + System.out.println("\n===== Detailed Course Info 6 ====="); + SCD.courseInfo(205); + SCD.graduateStudent(5555); + + System.out.println("\n===== Good Job! Bye! ====="); + } +} diff --git a/338/homework4/Course.java b/338/homework4/Course.java new file mode 100644 index 0000000..1b3c6e7 --- /dev/null +++ b/338/homework4/Course.java @@ -0,0 +1,32 @@ +/* +Class: + Course +Description: + Structure to represent a course in the school system + +*/ +public class Course { + public int id; + public String title; + public int instructorID; + public String location; + public int studentCount; + + public Course (int id, String title, int instructorID, String location) { + this.id = id; + this.title = title; + this.instructorID = instructorID; + this.location = location; + + this.studentCount = 0; + } + + // updates the room location of a given course ex. BIT-104 to BIT-110 + public void updateLocation(String newLocation) { + this.location = newLocation; + } + + public String toString() { + return this.id + " " + this.title; + } +} diff --git a/338/homework4/Enrolled.java b/338/homework4/Enrolled.java new file mode 100644 index 0000000..8f0893c --- /dev/null +++ b/338/homework4/Enrolled.java @@ -0,0 +1,13 @@ +// this class describes the relation between a student and a given class +// We allow students to be able to enroll in multiple classes with this class +public class Enrolled { + public int studentID; + public String studentName; + public int courseID; + public int courseTitle; + + Enrolled(int sID, String sName, int cID, String cTitle) { + this.studentID = sId; + this.studentName + } +} diff --git a/338/homework4/Instructor.java b/338/homework4/Instructor.java new file mode 100644 index 0000000..34942f5 --- /dev/null +++ b/338/homework4/Instructor.java @@ -0,0 +1,22 @@ +/* +Class: + Instructor +Description: + Structure to represent a instructor in the school system + +*/ +public class Instructor { + public int id; + public String name; + public String email; + public String phone; + public Instructor(int id , String name, String email, String phone) { + this.id = id; + this.name = name; + this.email = email; + this.phone = phone; + } + public String toString() { + return this.name; + } +} diff --git a/338/homework4/School.java b/338/homework4/School.java new file mode 100644 index 0000000..5f976d2 --- /dev/null +++ b/338/homework4/School.java @@ -0,0 +1,300 @@ +import java.util.ArrayList; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +// NOTE: there will probably only be one instance of a school object ever +public class School { + private ArrayList instructorList; + private ArrayList courseList; + private ArrayList studentList; + private String name; + + public School(/*String file,*/ String schoolName) { + this.instructorList = new ArrayList(); + this.courseList = new ArrayList(); + this.studentList = new ArrayList(); + + this.name = schoolName; + //readData(file); + } + public void readData(String filename) { + try { + BufferedReader reader = new BufferedReader(new FileReader(filename)); + // first line is how many instructors we want to add + int inst_count = Integer.parseInt(reader.readLine()); + for(int i =0;i