diff --git a/338/homework5/App.java b/338/homework5/App.java index ccd166f..dd6f822 100644 --- a/338/homework5/App.java +++ b/338/homework5/App.java @@ -9,10 +9,12 @@ Description: Builds a basic school data tracker import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; +import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.scene.layout.GridPane; +import javafx.scene.control.ListView; public class App extends Application { static public School school_; @@ -29,6 +31,12 @@ public class App extends Application { // add event listeners for the buttons returnButton.setOnAction(e-> stage.setScene(_prevScene)); + addButton.setOnAction(e->stage.setScene(Input.studentInputScene)); + + // add a responsive view to the for the student list + ListView dataView = new ListView(school_.uiGetStudents()); + _layout.add(dataView, 1,3,1,1); + // finally return a new scene with the finished layout Scene ret = new Scene(_layout, 1280, 720); return ret; @@ -45,7 +53,13 @@ public class App extends Application { _layout.add(setButton, 1,1,1,1); _layout.add(returnButton, 1,2,1,1); + // add responsive view of instructor list + ListView dataView = new ListView(school_.uiGetInstructors()); + _layout.add(dataView, 1,3,1,1); + returnButton.setOnAction(e -> stage.setScene(_prevScene)); + addButton.setOnAction(e -> stage.setScene(Input.instructorInputScene)); + Scene ret = new Scene(_layout, 1280, 720); return ret; } @@ -54,13 +68,22 @@ public class App extends Application { Button addButton = new Button("Add course"); Button deleteButton = new Button("Delete course"); + TextField courseField = new TextField(); Button returnButton = new Button("Return"); _layout.add(addButton, 1,0,1,1); _layout.add(deleteButton, 1,1,1,1); + _layout.add(courseField, 2,1,1,1); _layout.add(returnButton, 1,2,1,1); + addButton.setOnAction(e -> stage.setScene(Input.courseInputScene)); + deleteButton.setOnAction(e -> Input.courseDeletion(courseField.getText())); returnButton.setOnAction(e -> stage.setScene(_prevScene)); + + // add response data view for course list + ListView dataView = new ListView(school_.uiGetCourses()); + _layout.add(dataView, 1,3,1,1); + Scene ret = new Scene(_layout, 1280, 720); return ret; } @@ -86,6 +109,11 @@ public class App extends Application { Scene instMenu = setInstructorScene(stage, main_menu); Scene courMenu = setCourseScene(stage, main_menu); + // setup form pages + Input.initStudentInput(studMenu, stage); + Input.initInstructorInput(instMenu, stage); + Input.initCourseInput(courMenu, stage); + // now we can add the event listeners for our main menu as the other scenes now exist instButton.setOnAction(e-> stage.setScene(instMenu)); studButton.setOnAction(e-> stage.setScene(studMenu)); diff --git a/338/homework5/Course.java b/338/homework5/Course.java index 0a34e47..2ed3956 100644 --- a/338/homework5/Course.java +++ b/338/homework5/Course.java @@ -20,6 +20,7 @@ public class Course { } public String toString() { - return this.id + " - " + this.title; + // Instructions were not clear on what the toString should return so this is my interpretation + return id + " - " + title + " " + instructorID; } } diff --git a/338/homework5/Input.java b/338/homework5/Input.java new file mode 100644 index 0000000..ff1ada7 --- /dev/null +++ b/338/homework5/Input.java @@ -0,0 +1,160 @@ +/* This object will handle the user input forms for the application + * to clean up the front app.java portion + * */ +import javafx.scene.Scene; +import javafx.scene.layout.GridPane; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.control.Label; +import javafx.stage.Stage; +public class Input { + static public Scene studentInputScene; + static public Scene courseInputScene; + static public Scene instructorInputScene; + + static private void submitStudent(String id, String name, String courseID, String grade) { + int _id = Integer.parseInt(id); + int _courseID = Integer.parseInt(courseID); + float _grade = Float.parseFloat(grade); + + // right now we don't care about the letter grade so we'll just in put in whatever + App.school_.addStudent(_id, name, _courseID, _grade, "Z"); + } + static public void initStudentInput(Scene _return, Stage _stage) { + // each student takes: INT STRING INT DOUBLE + GridPane grid = new GridPane(); + + // first we'll add all the fields necessary + Label idLabel = new Label("ID"); + TextField idField = new TextField(); + grid.add(idLabel, 1, 0, 1,1); + grid.add(idField, 2, 0, 1,1); + + Label nmLabel = new Label("Name: "); + TextField nmField = new TextField(); + grid.add(nmLabel, 1, 1, 1, 1); + grid.add(nmField, 2, 1, 1, 1); + + Label cLabel = new Label("Course: "); + TextField cField = new TextField(); + grid.add(cLabel, 1,2,1,1); + grid.add(cField, 2,2,1,1); + + Label gLabel = new Label("Grade(Float): "); + TextField gField = new TextField(); + grid.add(gLabel, 1,3,1,1); + grid.add(gField, 2,3,1,1); + + // finally the buttons + Button retButton = new Button("Return"); + Button submit = new Button("Submit"); + grid.add(retButton, 1,4,1,1); + grid.add(submit, 2,4,1,1); + + retButton.setOnAction(e->_stage.setScene(_return)); + //submit.setOnAction(e->Input.Submit + Scene ret = new Scene(grid, 1280, 720); + studentInputScene = ret; + } + + public static void courseDeletion(String id) { + if(id.length() == 0 ) { + return; + } + // fallthrough to convert and delete the thing from the school system + App.school_.deleteCourse(Integer.parseInt(id)); + } + static private void submitCourse(String id, String title, String instID, String loc) { + int _id = Integer.parseInt(id); + int _instID = Integer.parseInt(instID); + App.school_.addCourse(_id, title, _instID, loc); + } + static public void initCourseInput(Scene _return, Stage _stage) { + GridPane grid = new GridPane(); + + // first we'll add all the fields necessary + Label idLabel = new Label("ID"); + TextField idField = new TextField(); + grid.add(idLabel, 1, 0, 1,1); + grid.add(idField, 2, 0, 1,1); + + Label nmLabel = new Label("Title: "); + TextField nmField = new TextField(); + grid.add(nmLabel, 1, 1, 1, 1); + grid.add(nmField, 2, 1, 1, 1); + + Label eLabel = new Label("Instructor ID: "); + TextField eField = new TextField(); + grid.add(eLabel, 1,2,1,1); + grid.add(eField, 2,2,1,1); + + Label pLabel = new Label("Location: "); + TextField pField = new TextField(); + grid.add(pLabel, 1,3,1,1); + grid.add(pField, 2,3,1,1); + + Button retButton = new Button("Return"); + Button submit = new Button("Submit"); + grid.add(retButton, 1,4,1,1); + grid.add(submit, 2,4,1,1); + + retButton.setOnAction(e->_stage.setScene(_return)); + // Finally we'll deal with submitting of the data + submit.setOnAction(e-> submitCourse( + idField.getText(), + nmField.getText(), + eField.getText(), + pField.getText() + )); + + Scene ret = new Scene(grid, 1280, 720); + courseInputScene = ret; + + } + static private void submitInstructor(String id, String name, String email, String phone) { + int _id = Integer.parseInt(id); + App.school_.addInstructor(_id, name, email, phone); + } + static public void initInstructorInput(Scene _return, Stage _stage) { + GridPane grid = new GridPane(); + + // first we'll add all the fields necessary + Label idLabel = new Label("ID"); + TextField idField = new TextField(); + grid.add(idLabel, 1, 0, 1,1); + grid.add(idField, 2, 0, 1,1); + + Label nmLabel = new Label("Name: "); + TextField nmField = new TextField(); + grid.add(nmLabel, 1, 1, 1, 1); + grid.add(nmField, 2, 1, 1, 1); + + Label eLabel = new Label("Email: "); + TextField eField = new TextField(); + grid.add(eLabel, 1,2,1,1); + grid.add(eField, 2,2,1,1); + + Label pLabel = new Label("PhoneNo: "); + TextField pField = new TextField(); + grid.add(pLabel, 1,3,1,1); + grid.add(pField, 2,3,1,1); + + Button retButton = new Button("Return"); + Button submit = new Button("Submit"); + grid.add(retButton, 1,4,1,1); + grid.add(submit, 2,4,1,1); + + retButton.setOnAction(e->_stage.setScene(_return)); + // Finally we'll deal with submitting of the data + submit.setOnAction(e-> submitInstructor( + idField.getText(), + nmField.getText(), + eField.getText(), + pField.getText() + )); + + Scene ret = new Scene(grid, 1280, 720); + instructorInputScene = ret; + } + +} diff --git a/338/homework5/Instructor.java b/338/homework5/Instructor.java index 1197cc1..e0b8797 100644 --- a/338/homework5/Instructor.java +++ b/338/homework5/Instructor.java @@ -10,6 +10,6 @@ public class Instructor { this.phone = phone; } public String toString() { - return this.name; + return id + " " + name + " " + email + " " + phone; } } diff --git a/338/homework5/School.java b/338/homework5/School.java index 95e24ee..a79c12b 100644 --- a/338/homework5/School.java +++ b/338/homework5/School.java @@ -40,6 +40,16 @@ public class School { courseList.set(k,c); } + public ObservableList uiGetInstructors() { + return instructorList; + } + public ObservableList uiGetCourses() { + return courseList; + } + public ObservableList uiGetStudents() { + return studentList; + } + public void editStudent(Student s) { int k = studentList.indexOf(s); studentList.set(k,s); diff --git a/338/homework5/Student.java b/338/homework5/Student.java index 6eef7e7..9a2b0f4 100644 --- a/338/homework5/Student.java +++ b/338/homework5/Student.java @@ -17,9 +17,9 @@ public class Student { this.status = "Enrolled"; } public String toString() { - return "Student number: " + this.id + "\n" + - "Name: " + this.name + "\n" + - "Status: " + this.status; + return "Student " + this.id + + " Name: " + this.name + + " Status: " + this.status; } public float averageGrade() { float sum = 0; diff --git a/338/homework5/Tests.java b/338/homework5/Tests.java new file mode 100644 index 0000000..f5cd66d --- /dev/null +++ b/338/homework5/Tests.java @@ -0,0 +1,3 @@ +// Unit testing some methods to make sure they produce correct results +public class UnitTest { +} diff --git a/338/homework5/makefile b/338/homework5/makefile index 23cf536..c21daa0 100644 --- a/338/homework5/makefile +++ b/338/homework5/makefile @@ -7,7 +7,7 @@ jfiles=App.java Course.java Instructor.java School.java Student.java cfiles=App all: $(jfiles) - $(cc) $(fxlib) $(jfiles) $(ctrl) + $(cc) -Xlint $(fxlib) $(jfiles) $(ctrl) run: $(cfile) $(env) $(fxlib) $(ctrl) $(cfiles)