Question: The program use a lambda expression event handler to validate user selection and act accordingly. If the user selection is valid against the registration business

The program use a lambda expression event handler to validate user selection and act accordingly. If the user selection is valid against the registration business rules, the program displays a registration confirmation message to the student for the selected course. Otherwise, the program displays an error message explaining the reason of the invalidation of the selection. The application maintains and displays a current list of registered courses. Additionally, the application maintains and displays a cumulative total credit hours the student has registered for thus far. Use these course codes, in this order, to test your application: IT2230 IT3349 IT2230 IT4782 IT4784

JAVA FX Register for Course

They told me there's a new version of the registration program written in Java FX that is gooey oriented and we should use it for our registration for this term, so I'm going to give it a try. So, I open up the application and I click on this drop-down list and I get a list of all of the courses that I can register for.

I heard that the IT2230 is a really good class about database and I would like to learn more about it so I will just select the IT2230 and it confirmed that I registered for this course, IT2230, and it maintains a current list of registered classes and it gives me a total of 3 credit hours that I have registered for so far. I want to register for another class. I want to expand my knowledge in the Java programming language, so I am going to select the IT3349, this is an intermediate Java programming class and it also confirms that I selected the IT3349. It added that class code, course code, to the currently registered classes and it updated the total credit hours for this term to six.

I wanted to take my Java skills to the next level I wanted to use Java in programming mobile devices so I'm going to select one of the mobile courses that are offered and I'm going to select oh! I think I made a mistake. I incorrectly selected the 2230, which is the database class, not the mobile class and it, the application knew that I had an invalid entry and said I'm already registered for IT2230 so I need to correct that. I would like to take the introductory class to mobile Android programming, the IT4782, so I select this one and it did confirm my registration for this class, IT4782. It added to the list of currently registered courses and it updated my total credit hours to nine. I want to register for one more class. Let's say I wanted to take the follow-up to the IT4782, which is the IT4784, and it is also complaining that this is an invalid entry because I cannot register for more than 9 credit hours, so this Java FX program seems to be working as expected and it is a lot easier to use than the console application counterpart of this application.

Program 1 followed by Course.java

package u4a1_javafxregisterforcourse;

import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.scene.layout.GridPane; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.geometry.HPos; import javafx.geometry.VPos; import javafx.scene.layout.RowConstraints; import javafx.scene.control.ComboBox; import javafx.scene.control.TextField;

public class U4A1_JavaFXRegisterForCourse extends Application { GridPane grid = new GridPane(); Label selectPromptLabel = new Label("Please select a course for which you want to register"); ComboBox coursesComboBox = new ComboBox<>(); Label confirmPromptLabel = new Label(""); Label registeredCoursesPromptLabel = new Label("You are currently registered for"); Label creditHourPromptLabel = new Label("Current total Credit Hours"); Label registeredCoursesLabel = new Label(""); Label creditHoursLabel = new Label("0");

Course choice; int totalCredit = 0; @Override public void start(Stage primaryStage) {

/* grid.setHgap(0); grid.setVgap(500);

grid.setGridLinesVisible(true); */ RowConstraints row0 = new RowConstraints(); RowConstraints row1 = new RowConstraints(); RowConstraints row2 = new RowConstraints(); RowConstraints row3 = new RowConstraints(); RowConstraints row4 = new RowConstraints(); row0.setPercentHeight(5); row1.setPercentHeight(50); row2.setPercentHeight(10); row3.setPercentHeight(5); row4.setPercentHeight(15); grid.getRowConstraints().addAll(row0, row1,row2, row3, row4);

grid.setAlignment(Pos.CENTER);

grid.setHgap(5); grid.setVgap(5); grid.add(selectPromptLabel, 0, 0); grid.setHalignment(selectPromptLabel, HPos.LEFT);

coursesComboBox.getItems().addAll( new Course("IT4782"), new Course("IT4784"), new Course("IT4786"), new Course("IT4789"), new Course("IT2230"), new Course("IT3345"), new Course("IT3349") ); coursesComboBox.setMaxWidth(Double.MAX_VALUE);

grid.add(coursesComboBox, 0, 1); grid.setValignment(coursesComboBox, VPos.TOP);

confirmPromptLabel.setTextFill(Color.RED); grid.add(confirmPromptLabel, 0, 2); grid.setHalignment(confirmPromptLabel, HPos.LEFT); grid.setValignment(confirmPromptLabel, VPos.TOP);

grid.add(registeredCoursesPromptLabel, 0, 3); grid.setHalignment(registeredCoursesPromptLabel, HPos.LEFT); grid.setValignment(registeredCoursesPromptLabel, VPos.TOP); grid.add(creditHourPromptLabel, 1, 3); grid.setHalignment(creditHourPromptLabel, HPos.LEFT); grid.setValignment(creditHourPromptLabel, VPos.TOP); grid.add(registeredCoursesLabel, 0, 4); grid.setHalignment(registeredCoursesLabel, HPos.LEFT); grid.setValignment(registeredCoursesLabel, VPos.TOP); registeredCoursesLabel.setStyle("-fx-background-color: #fff600;"); grid.add(creditHoursLabel, 1, 4); grid.setHalignment(creditHoursLabel, HPos.LEFT); grid.setValignment(creditHoursLabel, VPos.TOP); creditHoursLabel.setStyle("-fx-background-color: #fff600;"); Scene scene = new Scene(grid, 500, 500, Color.RED); primaryStage.setTitle("JavaFX Register for Course"); primaryStage.setScene(scene); primaryStage.show(); coursesComboBox.setOnAction(e -> { choice = coursesComboBox.getValue(); // TO DO - Add Code to: // Validate user selection (the choice Course object) // Display a confirmation or error message accordingly // Update display of registered courses and the total credit hours as appropriate

}); }

/** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }

Program 2

package u4a1_javafxregisterforcourse;

public class Course { private String code = ""; private boolean isRegisterdFor = false; public Course(String code){ this.code = code; } public void setCode(String code){ this.code = code; } public String getCode() { return this.code; } public void setIsRegisteredFor(boolean trueOrFalse){ this.isRegisterdFor = trueOrFalse; } public boolean getIsRegisteredFor() { return this.isRegisterdFor; } @Override public String toString(){ return this.getCode(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!