Schedule-Creator

Java GUI to create schedules for UNCG students
git clone git://git.wrycode.com/wrycode/archive/Schedule-Creator.git
Log | Files | Refs | README

commit a98ee15b1acaee0f98d6be3e424a9b52e0be0b7a
parent 2c8b1636ff1561e83ba8a5849cb5000f1651ec3f
Author: toldge <47599909+toldge@users.noreply.github.com>
Date:   Tue, 21 Apr 2020 19:05:26 -0400

Style guide changes (#69)

* add some methods for Section and Schedule

* change to fit the style guide

* Match style guide: fields, format, spacing, etc.

* Remove unnecessary comma
Diffstat:
MScheduleCreator/API/APIInterface.java | 3+--
MScheduleCreator/API/EmailAPI.java | 26++++++++++++++------------
MScheduleCreator/API/EmailAdapter.java | 15++++++++-------
MScheduleCreator/Adapter.java | 43++++++++++++++++++++++++++++++++-----------
MScheduleCreator/Tests.java | 4+---
MScheduleCreator/Translator.java | 24++++++++++++------------
MScheduleCreator/TranslatorInterface.java | 26+++++++++++++-------------
MScheduleCreator/controllers/CoursesController.java | 53+++++++++++++++++++++++++++++++++++------------------
MScheduleCreator/controllers/EmailPopupController.java | 35+++++++++++++++++++++++------------
MScheduleCreator/controllers/PrimaryController.java | 44+++++++++++++++++++++++++++-----------------
MScheduleCreator/controllers/RegistrationController.java | 58++++++++++++++++++++++++++++------------------------------
MScheduleCreator/models/Course.java | 27+++++++++++++++------------
MScheduleCreator/models/Schedule.java | 28++++++++++++++++------------
MScheduleCreator/models/Section.java | 11++++-------
MScheduleCreator/models/Semester.java | 32+++++++++++++++++---------------
15 files changed, 246 insertions(+), 183 deletions(-)

diff --git a/ScheduleCreator/API/APIInterface.java b/ScheduleCreator/API/APIInterface.java @@ -5,7 +5,7 @@ package ScheduleCreator.API; * * @author Ilyass Sfar * - * Last Updated: 3/18/2020 + * Last Updated: 4/21/2020 */ import com.mailjet.client.errors.MailjetException; import com.mailjet.client.errors.MailjetSocketTimeoutException; @@ -16,7 +16,6 @@ public interface APIInterface { * * @param _email The email that is being sent to, this comes from the user. * @param _message This is what is being sent in the email. - * @return * @throws MailjetException * @throws MailjetSocketTimeoutException */ diff --git a/ScheduleCreator/API/EmailAPI.java b/ScheduleCreator/API/EmailAPI.java @@ -5,7 +5,7 @@ package ScheduleCreator.API; * * @author Ilyass Sfar * - * Last Updated: 4/12/2020 + * Last Updated: 4/21/2020 */ import com.mailjet.client.errors.MailjetException; import com.mailjet.client.errors.MailjetSocketTimeoutException; @@ -30,9 +30,9 @@ public class EmailAPI implements APIInterface { /** * Send email's using an API. * - * @param _email The email that is being sent to, this comes from the user. + * @param _email The email address that is being sent to, this comes from + * the user. * @param _message This is what is being sent in the email. - * @return * @throws MailjetException * @throws MailjetSocketTimeoutException */ @@ -45,13 +45,13 @@ public class EmailAPI implements APIInterface { MailjetRequest request; MailjetResponse response; //Create a new client to send emails, using public and private api keys, and speify which version of the client is being used - client = new MailjetClient((apiPublicKey), (apiPrivateKey), new ClientOptions(clientVersion)); + client = new MailjetClient((EmailAPI.apiPublicKey), (EmailAPI.apiPrivateKey), new ClientOptions(EmailAPI.clientVersion)); request = new MailjetRequest(Emailv31.resource) .property(Emailv31.MESSAGES, new JSONArray() .put(new JSONObject() //The email that is being used to send, this is controled from the mailjet webiste .put(Emailv31.Message.FROM, new JSONObject() - .put("Email", sendEmail) + .put("Email", EmailAPI.sendEmail) .put("Name", "Schedule Creator")) //The email that is being send to .put(Emailv31.Message.TO, new JSONArray() @@ -73,14 +73,16 @@ public class EmailAPI implements APIInterface { } } - //Suporting method to "sendEmail", to validate emails before a api call is made. + /** + * Suporting method to "sendEmail", to validate emails before a api call is + * made. + * + * @param _email the email address to validate + * @return true if the email is valid, else false + */ public static boolean validate(String _email) { - Matcher matcher = validEmail.matcher(_email); - if (matcher.find()) { - return true; - } else { - return false; - } + Matcher matcher = EmailAPI.validEmail.matcher(_email); + return matcher.find(); } } diff --git a/ScheduleCreator/API/EmailAdapter.java b/ScheduleCreator/API/EmailAdapter.java @@ -5,7 +5,7 @@ package ScheduleCreator.API; * * @author Ilyass Sfar * - * Last Updated: 4/12/2020 + * Last Updated: 4/21/2020 */ import com.mailjet.client.errors.MailjetException; import com.mailjet.client.errors.MailjetSocketTimeoutException; @@ -19,7 +19,6 @@ public class EmailAdapter implements APIInterface { * * @param _email The email that is being sent to, this comes from the user. * @param _message This is what is being sent in the email. - * @return * @throws MailjetException * @throws MailjetSocketTimeoutException */ @@ -28,12 +27,14 @@ public class EmailAdapter implements APIInterface { EmailAdapter.thisApi.sendEmail(_email, _message); } + /** + * Validates whether the email is valid. + * + * @param _email + * @return true if the email is valid, else false + */ public static boolean validate(String _email) { - if (EmailAPI.validate(_email)) { - return true; - } else { - return false; - } + return EmailAPI.validate(_email); } } diff --git a/ScheduleCreator/Adapter.java b/ScheduleCreator/Adapter.java @@ -1,60 +1,81 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package ScheduleCreator; +/** + * An adapter that passes method calls to the translator. + * + * @author Nathan Tolodziecki + * Last Updated: 4/21/2020 + */ + import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; -/** - * - * @author Nathan Tolodziecki <Nathan Tolodziecki> - */ public class Adapter implements TranslatorInterface { - + final protected TranslatorInterface translator = new Translator(); + /** + * {@inheritDoc} + */ @Override public List<String> getSections(String _courseNumber, String _semester) { return this.translator.getSections(_courseNumber, _semester); } + /** + * {@inheritDoc} + */ @Override public String getFullText(String _resourceName) throws FileNotFoundException, IOException { return this.translator.getFullText(_resourceName); } + /** + * {@inheritDoc} + */ @Override public List<String> getCourses(String _semesterName) { return this.translator.getCourses(_semesterName); } + /** + * {@inheritDoc} + */ @Override public String getSectionInfo(Translator.choice _choice, String _semesterName, String _section) throws FileNotFoundException, IOException { return this.translator.getSectionInfo(_choice, _semesterName, _section); } + /** + * {@inheritDoc} + */ @Override public void saveCourse(String _course, String _semester) { this.translator.saveCourse(_course, _semester); } + /** + * {@inheritDoc} + */ @Override public void removeCourse(String _course, String _semester) { this.translator.removeCourse(_course, _semester); } + /** + * {@inheritDoc} + */ @Override public List<String> getSelectedCourses(String _semester) { return this.translator.getSelectedCourses(_semester); } + /** + * {@inheritDoc} + */ @Override public List<String> getSemesters() throws FileNotFoundException, IOException { return this.translator.getSemesters(); } - } diff --git a/ScheduleCreator/Tests.java b/ScheduleCreator/Tests.java @@ -5,13 +5,11 @@ package ScheduleCreator; * * @author Nick Econopouly, Ilyass Sfar * - * Last Updated: 4/6/2020 + * Last Updated: 4/21/2020 */ -import ScheduleCreator.API.EmailAdapter; import com.mailjet.client.errors.MailjetException; import com.mailjet.client.errors.MailjetSocketTimeoutException; import java.io.IOException; -import java.util.List; public class Tests { diff --git a/ScheduleCreator/Translator.java b/ScheduleCreator/Translator.java @@ -1,4 +1,12 @@ package ScheduleCreator; +/** + * This class is used to retrieve and modify persistent data for the + * application. + * + * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly + * + * Last Updated: 4/21/2020 + */ import java.io.BufferedReader; import java.io.File; @@ -15,14 +23,6 @@ import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * This class is used to retrieve and modify persistent data for the - * application. - * - * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly - * - * Last Updated: 3/17/2020 - */ public class Translator implements TranslatorInterface { // this is in the working directory, not the .jar @@ -201,7 +201,7 @@ public class Translator implements TranslatorInterface { public void saveCourse(String _course, String _semester) { //Adds new selected course to new line. - selectedCourseFile = new File(_semester + "_selected_courses.txt"); + Translator.selectedCourseFile = new File(_semester + "_selected_courses.txt"); try ( //Open file to add new classes. FileWriter output = new FileWriter(new File(_semester + "_selected_courses.txt"), true)) { //Adds new selected course to new line. @@ -221,10 +221,10 @@ public class Translator implements TranslatorInterface { @Override public void removeCourse(String _course, String _semester) { - selectedCourseFile = new File(_semester + "_selected_courses.txt"); + Translator.selectedCourseFile = new File(_semester + "_selected_courses.txt"); try { - List<String> courses = Files.readAllLines(selectedCourseFile.toPath()); + List<String> courses = Files.readAllLines(Translator.selectedCourseFile.toPath()); for (String course : courses) { if (course.equals(_course)) { courses.remove(course); @@ -232,7 +232,7 @@ public class Translator implements TranslatorInterface { } } - try ( FileWriter writer = new FileWriter(selectedCourseFile)) { + try ( FileWriter writer = new FileWriter(Translator.selectedCourseFile)) { for (String course : courses) { writer.append(course + "\n"); } diff --git a/ScheduleCreator/TranslatorInterface.java b/ScheduleCreator/TranslatorInterface.java @@ -1,15 +1,15 @@ package ScheduleCreator; +/** + * An interface to allow easier modularity of the adapter. + * + * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodzieki + * Last updated 04/21/2020 + */ import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; -/** - * An interface to allow easier modularity of the adapter. - * - * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodzieki - * Last updated 04/02/2020 - */ public interface TranslatorInterface { /** * @@ -18,9 +18,9 @@ public interface TranslatorInterface { * @throws java.io.FileNotFoundException */ abstract List<String> getSemesters() throws FileNotFoundException, IOException; - + abstract List<String> getSections(String _courseNumber, String _semester); - + /** * utility method to return the full text of the file using classpath * resource inside the jar. @@ -32,14 +32,14 @@ public interface TranslatorInterface { * @throws java.io.IOException */ abstract String getFullText(String _resourceName) throws FileNotFoundException, IOException; - + /** * * @param _semesterName * @return a List of courses (as Strings) available for the semester */ abstract List<String> getCourses(String _semesterName); - + /** * Get specific information about a section * @@ -50,16 +50,16 @@ public interface TranslatorInterface { * @throws java.io.FileNotFoundException */ abstract String getSectionInfo(Translator.choice _choice, String _semesterName, String _section) throws FileNotFoundException, IOException; - + abstract void saveCourse(String _course, String _semester); - + /** * Removes the selected course from the database. * * @param _course, _semester */ abstract void removeCourse(String _course, String _semester); - + /** * Returns a list of the selected courses. * diff --git a/ScheduleCreator/controllers/CoursesController.java b/ScheduleCreator/controllers/CoursesController.java @@ -5,7 +5,7 @@ package ScheduleCreator.controllers; * * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodzieki * - * Last Updated: 4/20/2020 + * Last Updated: 4/21/2020 */ import ScheduleCreator.Adapter; import java.io.IOException; @@ -94,6 +94,7 @@ public class CoursesController implements Initializable { /** * Set up the "Build Schedule" view and load the semesters. + * * @param url * @param rb */ @@ -103,7 +104,7 @@ public class CoursesController implements Initializable { this.loadSemesters(); this.NUM_ROWS = this.scheduleGridPane.getRowConstraints().size(); this.NUM_COLS = this.scheduleGridPane.getColumnConstraints().size(); - this.grid = new BorderPane[NUM_ROWS][NUM_COLS]; + this.grid = new BorderPane[this.NUM_ROWS][this.NUM_COLS]; this.drawGrid(); this.CRNPane.toFront(); @@ -116,15 +117,18 @@ public class CoursesController implements Initializable { } /** - * Run the action for each button if it's selected and the user types "Enter" + * Run the action for each button if it's selected and the user types + * "Enter" */ private void buttonSetup() { - Arrays.asList(addCourseButton, removeCourseButton, removeAllCoursesButton, selectAllButton, - sectionsButton, previousButton, nextButton, showCRNButton, emailCRNButton).forEach((button) -> { - // temporarily set the button as the default button (only while the button is in focus) - // https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Button.html#defaultButtonProperty - button.defaultButtonProperty().bind(button.focusedProperty()); - }); + Arrays.asList(this.addCourseButton, this.removeCourseButton, + this.removeAllCoursesButton, this.selectAllButton, + this.sectionsButton, this.previousButton, this.nextButton, + this.showCRNButton, this.emailCRNButton).forEach((button) -> { + // temporarily set the button as the default button (only while the button is in focus) + // https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Button.html#defaultButtonProperty + button.defaultButtonProperty().bind(button.focusedProperty()); + }); } /** @@ -148,8 +152,9 @@ public class CoursesController implements Initializable { } /** - * Called when "Submit" button is clicked; update the list of selected sections - * for generating schedules. + * Called when "Submit" button is clicked; update the list of selected + * sections for generating schedules. + * * @param _event */ public void setSections(ActionEvent _event) { @@ -174,13 +179,14 @@ public class CoursesController implements Initializable { } /** - * Called when a different semester is chosen and loads semester and course list. + * Called when a different semester is chosen and loads semester and course + * list. * * @param _event */ public void switchSemester(ActionEvent _event) { - String currentSemesterString = semesterComboBox.getValue(); + String currentSemesterString = this.semesterComboBox.getValue(); this.currentSemester = new Semester(semesterDirName(currentSemesterString)); this.loadAllCourses(); @@ -272,6 +278,7 @@ public class CoursesController implements Initializable { /** * Gets sections for a selected course and adds them to the sections * listview. + * * @param _event */ public void loadCourseSections(ActionEvent _event) { @@ -323,7 +330,7 @@ public class CoursesController implements Initializable { // ) searchField.textProperty().addListener(obs -> { - String filter = searchField.getText().toLowerCase(); + String filter = this.searchField.getText().toLowerCase(); // when there's nothing entered yet if (filter == null || filter.length() == 0) { // show all courses @@ -338,6 +345,7 @@ public class CoursesController implements Initializable { /** * Load list of semesters and show them in the dropdown menu + * * @throws IOException */ public void loadSemesters() throws IOException { @@ -425,6 +433,7 @@ public class CoursesController implements Initializable { /** * Returns true if all sections checkboxes are unchecked + * * @param _tab */ public boolean allUnselected(Tab _tab) { @@ -442,6 +451,7 @@ public class CoursesController implements Initializable { /** * Check all of the section checkboxes + * * @param _option * @param _tab */ @@ -471,7 +481,9 @@ public class CoursesController implements Initializable { } /** - * Show the current list of CRNs to the user when they click on the "Show CRNs" button + * Show the current list of CRNs to the user when they click on the "Show + * CRNs" button + * * @param _event */ public void showCRNs(ActionEvent _event) { @@ -502,6 +514,7 @@ public class CoursesController implements Initializable { /** * Draw a colored box for a course in the week schedule. + * * @param _section * @param _numberOfCampusCourses */ @@ -527,7 +540,7 @@ public class CoursesController implements Initializable { this.scheduleGridPane.getChildren().add(entryContainer); GridPane.setConstraints(entryContainer, col, row, 1, GridPane.REMAINING, HPos.CENTER, VPos.TOP); - BorderPane region = grid[row][col]; + BorderPane region = this.grid[row][col]; rect.heightProperty().bind(region.heightProperty().subtract(2).multiply(_section.getDurationHours())); rect.widthProperty().bind(region.widthProperty().subtract(2)); this.entries.add(entryContainer); @@ -606,8 +619,9 @@ public class CoursesController implements Initializable { } /** - * Update the grid and other UI elements on the right side to reflect - * the currently selected sections. + * Update the grid and other UI elements on the right side to reflect the + * currently selected sections. + * * @param _schedule */ public void loadSchedule(Schedule _schedule) { @@ -633,6 +647,7 @@ public class CoursesController implements Initializable { /** * Load schedule for the next semester + * * @param _event */ public void loadNextSchedule(ActionEvent _event) { @@ -646,6 +661,7 @@ public class CoursesController implements Initializable { /** * Load schedule for the previous semester + * * @param _event */ public void loadPrevSchedule(ActionEvent _event) { @@ -657,6 +673,7 @@ public class CoursesController implements Initializable { /** * Open the popup for when the user clicks "Email CRN" + * * @param event */ public void popupAction(ActionEvent event) { diff --git a/ScheduleCreator/controllers/EmailPopupController.java b/ScheduleCreator/controllers/EmailPopupController.java @@ -3,12 +3,11 @@ package ScheduleCreator.controllers; /** * Controller for email api popup * - * @author Ilyass Sfar + * @author Ilyass Sfar, Nathan Tolodziecki * - * Last Updated: 4/12/2020 + * Last Updated: 4/21/2020 */ import ScheduleCreator.API.EmailAdapter; -import ScheduleCreator.models.Section; import com.mailjet.client.errors.MailjetException; import com.mailjet.client.errors.MailjetSocketTimeoutException; import javafx.event.ActionEvent; @@ -27,34 +26,46 @@ public class EmailPopupController { @FXML private Button sendBtn; - //Calls email api + /** + * Calls the email API, displaying an alert if the email is invalid. + * + * @param event + * @throws MailjetException + * @throws MailjetSocketTimeoutException + */ @FXML public void sendEmail(ActionEvent event) throws MailjetException, MailjetSocketTimeoutException { - if (EmailAdapter.validate(emailTF.getText())) { + if (EmailAdapter.validate(this.emailTF.getText())) { EmailAdapter testAPI = new EmailAdapter(); - testAPI.sendEmail(emailTF.getText(), EmailPopupController.getCRNS()); - Stage stage = (Stage) sendBtn.getScene().getWindow(); + testAPI.sendEmail(this.emailTF.getText(), EmailPopupController.getCRNS()); + Stage stage = (Stage) this.sendBtn.getScene().getWindow(); stage.close(); } else { Alert alert = new Alert(Alert.AlertType.ERROR, "", ButtonType.OK); alert.setTitle("Invalid Email"); alert.setHeaderText("Invalid Email"); - alert.setContentText("The given email " + "\"" + emailTF.getText() + "\"" + " is NOT valid."); + alert.setContentText("The given email " + "\"" + this.emailTF.getText() + "\"" + " is NOT valid."); alert.showAndWait(); } } + /** + * Retrieves the CRNs for the courses that the user has selected, displaying + * an error popup if none have been selected. + * + * @return The user-selected CRNs + */ public static String getCRNS() { //Check if the user has choosen any courses when pressing the email button, if not a error popup is shown notifying the user - if (CoursesController.currentSemester == null || CoursesController.currentSemester.getSelectedCourses().size() == 0) { + if (CoursesController.currentSemester == null || CoursesController.currentSemester.getSelectedCourses().isEmpty()) { Alert alert = new Alert(Alert.AlertType.ERROR, "You have not selected a semseter or any courses", ButtonType.OK); alert.showAndWait(); } - //If the user has selected some course then the crns for the coruses are rietrived. + //If the user has selected some course then the crns for the courses are retrieved. StringBuilder content = new StringBuilder(); - for (Section section : CoursesController.currentSemester.getSchedules().get(CoursesController.currentScheduleIndex).getAddedSections()) { + CoursesController.currentSemester.getSchedules().get(CoursesController.currentScheduleIndex).getAddedSections().forEach((section) -> { content.append(section.getID() + "-" + section.getSectionNumber() + " | " + section.getCRN() + "\n"); - } + }); return content.toString(); } diff --git a/ScheduleCreator/controllers/PrimaryController.java b/ScheduleCreator/controllers/PrimaryController.java @@ -5,9 +5,8 @@ package ScheduleCreator.controllers; * * @author Jamison Valentine * - * Last Updated: 4/20/2020 + * Last Updated: 4/21/2020 */ - import com.sun.javafx.css.StyleManager; import javafx.event.ActionEvent; import javafx.fxml.FXMLLoader; @@ -47,29 +46,34 @@ public class PrimaryController implements Initializable { /** * Sets the current view of the app to the course selection view. + * * @throws Exception */ public void changeToSelectCourses() throws Exception { //New FXML Loader to render the next view. Parent root = FXMLLoader.load(getClass().getResource("/ScheduleCreator/resources/views/select_courses.fxml")); - mainContent.getChildren().clear(); - mainContent.getChildren().add(root); + this.mainContent.getChildren().clear(); + this.mainContent.getChildren().add(root); this.setCurrentItem(this.schedMenuItem); } /** * Sets the current menu item to the given argument. + * * @param _menuItem */ private void setCurrentItem(HBox _menuItem) { - if (this.currentMenuItem != null) this.unhighlight(this.currentMenuItem); + if (this.currentMenuItem != null) { + this.unhighlight(this.currentMenuItem); + } this.currentMenuItem = _menuItem; this.highlight(this.currentMenuItem); } /** * Changes the appropriate text color to white to indicate current focus. + * * @param _menuItem */ private void highlight(HBox _menuItem) { @@ -79,6 +83,7 @@ public class PrimaryController implements Initializable { /** * Undoes highlighting of previously focused item. + * * @param _menuItem */ private void unhighlight(HBox _menuItem) { @@ -87,18 +92,20 @@ public class PrimaryController implements Initializable { } /** - * Changes application view to registration + * Changes application view to registration. + * * @throws Exception */ public void changeToRegistrationScreen() throws Exception { Parent root = FXMLLoader.load(getClass().getResource("/ScheduleCreator/resources/views/registration_screen.fxml")); - mainContent.getChildren().clear(); - mainContent.getChildren().add(root); + this.mainContent.getChildren().clear(); + this.mainContent.getChildren().add(root); this.setCurrentItem(this.regMenuItem); } /** - * Highlight menu item when user mouses over it + * Highlight menu item when user mouses over it. + * * @param _event */ public void hoverItem(MouseEvent _event) { @@ -107,17 +114,20 @@ public class PrimaryController implements Initializable { } /** - * Unhighlight menu item when user mouses over it + * Un-highlight menu item when user mouses over it. + * * @param _event */ public void unhoverItem(MouseEvent _event) { HBox item = (HBox) _event.getSource(); - if (item != this.currentMenuItem) + if (item != this.currentMenuItem) { this.unhighlight(item); + } } /** * Toggle visibility of menu with the toggleMenu ToggleButton. + * * @param _event */ @FXML @@ -137,12 +147,11 @@ public class PrimaryController implements Initializable { } /** - - * Toggle darkMode css with the toggleDarkMode ToggleButton + * Toggle darkMode css with the toggleDarkMode ToggleButton. */ @FXML private void toggleDarkMode(ActionEvent event) { - if (darkMode.isSelected()) { + if (this.darkMode.isSelected()) { Application.setUserAgentStylesheet(Application.STYLESHEET_MODENA); StyleManager.getInstance().addUserAgentStylesheet("ScheduleCreator/resources/Darkmode.css"); } else { @@ -152,7 +161,9 @@ public class PrimaryController implements Initializable { } /** - * Set up the primary view with the menu and the "Build Schedule" window visible by default + * Set up the primary view with the menu and the "Build Schedule" window + * visible by default. + * * @param url * @param rb */ @@ -170,4 +181,4 @@ public class PrimaryController implements Initializable { System.out.println("Something went wrong"); } } -}- \ No newline at end of file +} diff --git a/ScheduleCreator/controllers/RegistrationController.java b/ScheduleCreator/controllers/RegistrationController.java @@ -3,25 +3,17 @@ package ScheduleCreator.controllers; /** * Controller for Registration * - * @author Ilyass Sfar, Jamison Valentine + * @author Ilyass Sfar, Jamison Valentine, Nathan Tolodziecki * - * Last Updated: 4/8/2020 + * Last Updated: 4/21/2020 */ -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; import javafx.application.Platform; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Node; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.scene.web.WebEngine; import javafx.scene.web.WebHistory; import javafx.scene.web.WebView; -import javafx.stage.Stage; public class RegistrationController { @@ -30,47 +22,53 @@ public class RegistrationController { private WebEngine engine; - //loads the uncg geine webpage as soon as the user acesses the registration screen + /** + * loads the uncg geine webpage as soon as the user acesses the registration + * screen + */ public void initialize() { - engine = webview.getEngine(); - engine.load("https://ssb.uncg.edu/"); + this.engine = this.webview.getEngine(); + this.engine.load("https://ssb.uncg.edu/"); } - //Forward and Backwards buttons based on https://stackoverflow.com/questions/18928333 - //Button to go back to pervious web page + /** + * Forward and Backwards buttons based on + * https://stackoverflow.com/questions/18928333 Button to go back to + * previous web page + */ @FXML void goBackWeb(ActionEvent event) { - final WebHistory history = engine.getHistory(); + final WebHistory history = this.engine.getHistory(); ObservableList<WebHistory.Entry> entryList = history.getEntries(); int currentIndex = history.getCurrentIndex(); - Platform.runLater(new Runnable() { - public void run() { - history.go(-1); - } + Platform.runLater(() -> { + history.go(-1); }); - engine.load(entryList.get(currentIndex > 0 ? currentIndex - 1 : currentIndex).getUrl()); + this.engine.load(entryList.get(currentIndex > 0 ? currentIndex - 1 : currentIndex).getUrl()); } - //Button to go forward to pervious web page + /** + * Button to go forward to pervious web page. + */ @FXML void goForwardWeb(ActionEvent event) { - final WebHistory history = engine.getHistory(); + final WebHistory history = this.engine.getHistory(); ObservableList<WebHistory.Entry> entryList = history.getEntries(); int currentIndex = history.getCurrentIndex(); - Platform.runLater(new Runnable() { - public void run() { - history.go(1); - } + Platform.runLater(() -> { + history.go(1); }); - engine.load(entryList.get(currentIndex < entryList.size() - 1 ? currentIndex + 1 : currentIndex).getUrl()); + this.engine.load(entryList.get(currentIndex < entryList.size() - 1 ? currentIndex + 1 : currentIndex).getUrl()); } - //Button to reload current web page + /** + * Button to reload current web page. + */ @FXML void reloadWeb(ActionEvent event) { - engine.reload(); + this.engine.reload(); } } diff --git a/ScheduleCreator/models/Course.java b/ScheduleCreator/models/Course.java @@ -5,9 +5,8 @@ package ScheduleCreator.models; * * @author Jamison Valentine * - * Last Updated: 4/19/2020 + * Last Updated: 4/21/2020 */ - import ScheduleCreator.Adapter; import java.util.ArrayList; import java.util.List; @@ -28,13 +27,13 @@ public class Course { this.courseNumber = _name.substring(4, 7); this.abbreviation = _name.substring(0, 4); this.id = this.abbreviation + this.courseNumber; - this.loadSectionsFromFile( _semester); + this.loadSectionsFromFile(_semester); } //================= GETTERS =============== - /** * Returns course abbreviation and number. + * * @return */ public String getID() { @@ -42,8 +41,9 @@ public class Course { } /** - * Returns course abbreviation, number, and title - * such as "CSC 340 - Software Engineering" + * Returns course abbreviation, number, and title such as "CSC 340 - + * Software Engineering" + * * @return */ public String getFullText() { @@ -52,7 +52,8 @@ public class Course { /** * Returns department/course abbreviation (i.e. CSC) - * @return + * + * @return */ public String getAbbreviation() { return abbreviation; @@ -60,7 +61,8 @@ public class Course { /** * Returns appropriate course number by itself. - * @return + * + * @return */ public String getCourseNumber() { return courseNumber; @@ -68,14 +70,16 @@ public class Course { /** * Returns available sections corresponding to this course. + * * @return */ public List<Section> getSections() { return this.sections; } - /** Loads available sections corresponding to this class for the - * given semester + /** + * Loads available sections corresponding to this class for the given + * semester * * @param _semester */ @@ -107,8 +111,7 @@ public class Course { Section newSection = new Section(this.id, sectionNumber, daysAndTimes, location, instructor, CRN, false); this.sections.add(newSection); - } - else if ((m2.matches())) { + } else if ((m2.matches())) { CRN = m2.group(1).trim(); sectionNumber = m2.group(2).trim(); instructor = m2.group(4).trim(); diff --git a/ScheduleCreator/models/Schedule.java b/ScheduleCreator/models/Schedule.java @@ -6,9 +6,9 @@ import java.util.List; /** * This class keeps track of added course sections and produces CRNs. * - * @author Jamison Valentine + * @author Jamison Valentine, Nathan Tolodziecki * - * Last Updated: 3/31/2020 + * Last Updated: 4/21/2020 */ public class Schedule { @@ -20,8 +20,9 @@ public class Schedule { } /** - * Checks to see if this _newSection can be added to the schedule - * without incident + * Checks to see if this _newSection can be added to the schedule without + * incident + * * @param _newSection * @return */ @@ -29,13 +30,17 @@ public class Schedule { if (this.addedSections.size() > 0 && !_newSection.isOnline) { List<Section> campusSections = new ArrayList(); - for (Section section : addedSections) if (!section.isOnline) campusSections.add(section); + this.addedSections.stream().filter((section) -> (!section.isOnline)).forEachOrdered((section) -> { + campusSections.add(section); + }); for (Section existingSection : campusSections) { Boolean sameDay = false; for (char day : _newSection.getDays().toCharArray()) { - if (existingSection.getDays().contains("" + day)) sameDay = true; + if (existingSection.getDays().contains("" + day)) { + sameDay = true; + } } if (sameDay) { @@ -58,11 +63,11 @@ public class Schedule { } @Override - public String toString() { + public String toString() { StringBuilder string = new StringBuilder(); - for (Section section : this.addedSections) { - string.append("(" + section.getCourseID() + " - " + section.getSectionNumber() + ")\n"); - } + this.addedSections.forEach((section) -> { + string.append("(").append(section.getCourseID()).append(" - ").append(section.getSectionNumber()).append(")\n"); + }); return string.toString(); } -}- \ No newline at end of file +} diff --git a/ScheduleCreator/models/Section.java b/ScheduleCreator/models/Section.java @@ -5,9 +5,8 @@ package ScheduleCreator.models; * * @author Jamison Valentine * - * Last Updated: 4/19/2020 + * Last Updated: 4/21/2020 */ - import java.util.Scanner; public class Section { @@ -37,7 +36,6 @@ public class Section { this.setTimes(); } - //================= GETTERS =============== public String getID() { return this.id; @@ -45,6 +43,7 @@ public class Section { /** * Return class time as a decimal (i.e. 1.5 hours) + * * @return */ public double getDurationHours() { @@ -97,7 +96,7 @@ public class Section { @Override public String toString() { - String string = ""; + String string; if (!this.isOnline) { string = this.sectionNumber + " | " + this.daysAndTimes + " | " @@ -110,7 +109,6 @@ public class Section { } //========================= SETTERS ============================= - /** * Extracts time from string with course meeting days and time information. */ @@ -141,4 +139,4 @@ public class Section { this.endTime = end; } -}- \ No newline at end of file +} diff --git a/ScheduleCreator/models/Semester.java b/ScheduleCreator/models/Semester.java @@ -10,7 +10,7 @@ import java.util.List; * * @author Nick Econopouly, Jamison Valentine * - * Last Updated: 3/31/2020 + * Last Updated: 4/21/2020 */ public class Semester { @@ -36,8 +36,7 @@ public class Semester { if (this.selectedSections.get(_course) == null) { list.add(_section); this.selectedSections.put(_course, list); - } - else { + } else { //Checks to see if this section is already selected. List<Section> sectionList = this.selectedSections.get(_course); @@ -86,22 +85,18 @@ public class Semester { newSchedule.addSection(section); validSchedules.add(newSchedule); } - } - - //If there is more than one course in the list + } //If there is more than one course in the list else { //Remove the current course from the remaining list List<Course> remainingCourses = new ArrayList(selectedCourses); remainingCourses.remove(course); - for (Section section : this.selectedSections.get(course)) { - for (Schedule schedule : generateSchedules(remainingCourses)) { - if (schedule.addSection(section)) { - validSchedules.add(schedule); - } - } - } + this.selectedSections.get(course).forEach((section) -> { + generateSchedules(remainingCourses).stream().filter((schedule) -> (schedule.addSection(section))).forEachOrdered((schedule) -> { + validSchedules.add(schedule); + }); + }); } return validSchedules; } @@ -110,13 +105,17 @@ public class Semester { List<String> list = this.adapter.getSelectedCourses(this.name); if (!list.isEmpty()) { - for (String courseName : list) { + list.forEach((courseName) -> { Course course = new Course(courseName, this.name); this.selectedSections.put(new Course(courseName, this.name), course.getSections()); - } + }); } } + /** + * Removes the course from the Semester. + * @param _course + */ public void removeCourse(String _course) { for (Course course : this.selectedSections.keySet()) { @@ -130,6 +129,9 @@ public class Semester { @Override public boolean equals(Object _obj) { + if(!(_obj instanceof Semester)){ + return false; + } Semester otherSemester = (Semester) _obj; return this.name.equalsIgnoreCase(otherSemester.getName()); }