From cdd9cf296fe07bedf31652f582a92d9dd1fab14c Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Sun, 5 May 2019 21:08:43 -0700 Subject: [PATCH 1/5] 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 Date: Sun, 5 May 2019 21:12:35 -0700 Subject: [PATCH 2/5] huffman decoder --- 370/homework/huff.py | 31 +++++++++++++++++++++++++++++++ 370/homework/huffman.py | 32 +++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 370/homework/huff.py diff --git a/370/homework/huff.py b/370/homework/huff.py new file mode 100644 index 0000000..cead790 --- /dev/null +++ b/370/homework/huff.py @@ -0,0 +1,31 @@ +class Node(): + def __init__(self, c, weight): + self.c = c + self.freq = weight + self.left = None + self.right = None + + def __repr__(self): + return f'{self.c}|{self.freq}' + +class Huffman: + def __init__(self, string): + self.heap = [] + self.charMap = self.charFrequencies(string) + + def charFrequencies(self, string): + ret = [] + for i in string: + if i in ret: + ret[i] += 1 + else: + ret[i] = 1 + return ret.sort() + +if __name__ == '__main__': + text = input() + binary = input() + + # encode the first given string to build a tree from it + huff = Huffman(text) + print(huff.charMap) \ No newline at end of file diff --git a/370/homework/huffman.py b/370/homework/huffman.py index e427916..9e55470 100644 --- a/370/homework/huffman.py +++ b/370/homework/huffman.py @@ -2,12 +2,12 @@ import queue class Node(): def __init__(self, c, weight): self.c = c - self.weight = weight + self.freq = weight self.left = None self.right = None def __repr__(self): - return f'{self.c}|{self.weight}' + return f'{self.c}|{self.freq}' class MinHeap(): def __init__(self): @@ -58,12 +58,16 @@ class MinHeap(): self.__heapifyDown(mini) def printChar(self, c): - # Traverse through the tree until we get to a leaf then back out - tmp = self.data[0] - # keep going until we hit a leaf - while tmp.left is not None or tmp.right is not None: - # 0 if left : 1 if right - continue + # TODO: this method + curr = self.data[0] + for i in bin: + if i == '1' and curr.right is not None: + curr = curr.right + if i == '0' and curr.left is not None: + curr = curr.left + + + def main(): @@ -97,10 +101,10 @@ def frequencyMap(string): # otherwise increment the frequency of that node for k in ret: if k.c == i: - k.weight += 1 + k.freq += 1 # Sort the charmap based on the frequencies - ret.sort(key=lambda x: x.weight) + ret.sort(key=lambda x: x.freq) return ret @@ -110,9 +114,15 @@ def buildMinHeap(freqs): while _queue.qsize() >= 2: left = _queue.get() right = _queue.get() - weight = left.weight + right.weight + weight = left.freq+ right.freq root = Node('*', weight) + + # insert the new sub-tree into the minheap and add the tree to the queue + heap.insert(root) + _queue.put(root) + # Once there is one item in the queue left we can simply return the new thing + heap.print() return heap From cde09178f6198614a1231f6b83e1491343bf77cb Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Mon, 6 May 2019 18:36:08 -0700 Subject: [PATCH 3/5] renamed files to fit the mysterious gradle scripts --- 338/homework4/{App.java => T1.java} | 2 +- 338/homework4/makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename 338/homework4/{App.java => T1.java} (99%) diff --git a/338/homework4/App.java b/338/homework4/T1.java similarity index 99% rename from 338/homework4/App.java rename to 338/homework4/T1.java index 2f211bd..b298831 100644 --- a/338/homework4/App.java +++ b/338/homework4/T1.java @@ -6,7 +6,7 @@ Description: Builds a basic school data tracker Course information is also available Input is read from file */ -public class App { +public class T1 { public static void main(String[] args) { String dataFile1 = "data1.txt"; String dataFile2 = "data2.txt"; diff --git a/338/homework4/makefile b/338/homework4/makefile index 18fa62a..e7b852b 100644 --- a/338/homework4/makefile +++ b/338/homework4/makefile @@ -1,8 +1,8 @@ all: - javac App.java Course.java Instructor.java School.java Student.java + javac T1.java Course.java Instructor.java School.java Student.java run: all - @java App + @java T1 clean: rm -f *class From 2012f2bd98c56e79fe3e251782749493a08db1cf Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Mon, 6 May 2019 18:37:34 -0700 Subject: [PATCH 4/5] removed stale class --- 338/homework4/Enrolled.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 338/homework4/Enrolled.java diff --git a/338/homework4/Enrolled.java b/338/homework4/Enrolled.java deleted file mode 100644 index 8f0893c..0000000 --- a/338/homework4/Enrolled.java +++ /dev/null @@ -1,13 +0,0 @@ -// 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 - } -} From 319c51e234fb7ef905d2562db02fff86fe05a4d0 Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Mon, 6 May 2019 22:26:01 -0700 Subject: [PATCH 5/5] added date for 0.2 points wew --- 338/homework4/T1.java | 1 + 1 file changed, 1 insertion(+) diff --git a/338/homework4/T1.java b/338/homework4/T1.java index b298831..9b2c8b6 100644 --- a/338/homework4/T1.java +++ b/338/homework4/T1.java @@ -1,5 +1,6 @@ /* Author: Alejandro Santillana +Date: May 6, 2019 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.