courses additions and deletions working, studdent additions working
instructor additions working
This commit is contained in:
parent
fd380c6fe7
commit
c48fd13f0d
@ -9,10 +9,12 @@ Description: Builds a basic school data tracker
|
|||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
|
||||||
public class App extends Application {
|
public class App extends Application {
|
||||||
static public School school_;
|
static public School school_;
|
||||||
@ -29,6 +31,12 @@ public class App extends Application {
|
|||||||
|
|
||||||
// add event listeners for the buttons
|
// add event listeners for the buttons
|
||||||
returnButton.setOnAction(e-> stage.setScene(_prevScene));
|
returnButton.setOnAction(e-> stage.setScene(_prevScene));
|
||||||
|
addButton.setOnAction(e->stage.setScene(Input.studentInputScene));
|
||||||
|
|
||||||
|
// add a responsive view to the for the student list
|
||||||
|
ListView<Student> dataView = new ListView<Student>(school_.uiGetStudents());
|
||||||
|
_layout.add(dataView, 1,3,1,1);
|
||||||
|
|
||||||
// finally return a new scene with the finished layout
|
// finally return a new scene with the finished layout
|
||||||
Scene ret = new Scene(_layout, 1280, 720);
|
Scene ret = new Scene(_layout, 1280, 720);
|
||||||
return ret;
|
return ret;
|
||||||
@ -45,7 +53,13 @@ public class App extends Application {
|
|||||||
_layout.add(setButton, 1,1,1,1);
|
_layout.add(setButton, 1,1,1,1);
|
||||||
_layout.add(returnButton, 1,2,1,1);
|
_layout.add(returnButton, 1,2,1,1);
|
||||||
|
|
||||||
|
// add responsive view of instructor list
|
||||||
|
ListView<Instructor> dataView = new ListView<Instructor>(school_.uiGetInstructors());
|
||||||
|
_layout.add(dataView, 1,3,1,1);
|
||||||
|
|
||||||
returnButton.setOnAction(e -> stage.setScene(_prevScene));
|
returnButton.setOnAction(e -> stage.setScene(_prevScene));
|
||||||
|
addButton.setOnAction(e -> stage.setScene(Input.instructorInputScene));
|
||||||
|
|
||||||
Scene ret = new Scene(_layout, 1280, 720);
|
Scene ret = new Scene(_layout, 1280, 720);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -54,13 +68,22 @@ public class App extends Application {
|
|||||||
|
|
||||||
Button addButton = new Button("Add course");
|
Button addButton = new Button("Add course");
|
||||||
Button deleteButton = new Button("Delete course");
|
Button deleteButton = new Button("Delete course");
|
||||||
|
TextField courseField = new TextField();
|
||||||
Button returnButton = new Button("Return");
|
Button returnButton = new Button("Return");
|
||||||
|
|
||||||
_layout.add(addButton, 1,0,1,1);
|
_layout.add(addButton, 1,0,1,1);
|
||||||
_layout.add(deleteButton, 1,1,1,1);
|
_layout.add(deleteButton, 1,1,1,1);
|
||||||
|
_layout.add(courseField, 2,1,1,1);
|
||||||
_layout.add(returnButton, 1,2,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));
|
returnButton.setOnAction(e -> stage.setScene(_prevScene));
|
||||||
|
|
||||||
|
// add response data view for course list
|
||||||
|
ListView<Course> dataView = new ListView<Course>(school_.uiGetCourses());
|
||||||
|
_layout.add(dataView, 1,3,1,1);
|
||||||
|
|
||||||
Scene ret = new Scene(_layout, 1280, 720);
|
Scene ret = new Scene(_layout, 1280, 720);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -86,6 +109,11 @@ public class App extends Application {
|
|||||||
Scene instMenu = setInstructorScene(stage, main_menu);
|
Scene instMenu = setInstructorScene(stage, main_menu);
|
||||||
Scene courMenu = setCourseScene(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
|
// now we can add the event listeners for our main menu as the other scenes now exist
|
||||||
instButton.setOnAction(e-> stage.setScene(instMenu));
|
instButton.setOnAction(e-> stage.setScene(instMenu));
|
||||||
studButton.setOnAction(e-> stage.setScene(studMenu));
|
studButton.setOnAction(e-> stage.setScene(studMenu));
|
||||||
|
@ -20,6 +20,7 @@ public class Course {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
160
338/homework5/Input.java
Normal file
160
338/homework5/Input.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,6 +10,6 @@ public class Instructor {
|
|||||||
this.phone = phone;
|
this.phone = phone;
|
||||||
}
|
}
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
return id + " " + name + " " + email + " " + phone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,16 @@ public class School {
|
|||||||
courseList.set(k,c);
|
courseList.set(k,c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<Instructor> uiGetInstructors() {
|
||||||
|
return instructorList;
|
||||||
|
}
|
||||||
|
public ObservableList<Course> uiGetCourses() {
|
||||||
|
return courseList;
|
||||||
|
}
|
||||||
|
public ObservableList<Student> uiGetStudents() {
|
||||||
|
return studentList;
|
||||||
|
}
|
||||||
|
|
||||||
public void editStudent(Student s) {
|
public void editStudent(Student s) {
|
||||||
int k = studentList.indexOf(s);
|
int k = studentList.indexOf(s);
|
||||||
studentList.set(k,s);
|
studentList.set(k,s);
|
||||||
|
@ -17,9 +17,9 @@ public class Student {
|
|||||||
this.status = "Enrolled";
|
this.status = "Enrolled";
|
||||||
}
|
}
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Student number: " + this.id + "\n" +
|
return "Student " + this.id +
|
||||||
"Name: " + this.name + "\n" +
|
" Name: " + this.name +
|
||||||
"Status: " + this.status;
|
" Status: " + this.status;
|
||||||
}
|
}
|
||||||
public float averageGrade() {
|
public float averageGrade() {
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
|
3
338/homework5/Tests.java
Normal file
3
338/homework5/Tests.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Unit testing some methods to make sure they produce correct results
|
||||||
|
public class UnitTest {
|
||||||
|
}
|
@ -7,7 +7,7 @@ jfiles=App.java Course.java Instructor.java School.java Student.java
|
|||||||
cfiles=App
|
cfiles=App
|
||||||
|
|
||||||
all: $(jfiles)
|
all: $(jfiles)
|
||||||
$(cc) $(fxlib) $(jfiles) $(ctrl)
|
$(cc) -Xlint $(fxlib) $(jfiles) $(ctrl)
|
||||||
|
|
||||||
run: $(cfile)
|
run: $(cfile)
|
||||||
$(env) $(fxlib) $(ctrl) $(cfiles)
|
$(env) $(fxlib) $(ctrl) $(cfiles)
|
||||||
|
Loading…
Reference in New Issue
Block a user