Question: Use JavaFX to create an application that determines the amount of a room reservation at a hotel. The user interface will enable the entry of
Use JavaFX to create an application that determines the amount of a room reservation at a hotel. The user interface will enable the entry of the number of nights to stay and room "options" like the category of the room, smokingonsmoking, and breakfast included. You will need to write code to handle button clicks and then determine values in TextField, ComboBox and CheckBox objects. The assignment is designed to use multiple "tiers" or levels with each tier being a separate class. The user interface tier will be the ReserveRoomGui class. The business logic tier will be the Reservation class. Normally the application (the class with the main method) would be in a separate class also. However the main method has just one statement so we will place it in the the ReserveRoomGui class.
Create a project named ReserveRoom. Create a package named edu.arizonastate.reserveroom. Put the classes described below in this package. Create two new classes in this package - ReserveRoomGui and Reservation.
The following requirements apply to the ReserveRoomGui class.
Create a main method in the ReserveRoomGui class.
Create a user interface like this example. You could use several layout managers but I recommend either the FlowPane or GridPane.
Exit the application when the user clicks the Exit button in the user interface.
Display the total amount due in the user interface when the user clicks the Reserve button. Get the data from the user interface and use that to create a Reservation object. Use the Reservation object to call the getAmountDue method. That method will return the amount due for the reservation. (NOTE: The getAmountDue method does not have any parameters.) Format the amount due as dollars and cents.
Use a TextField to enable the user to enter the guest name for the reservation. This value cannot be null/empty. Update the TextField in the user interface with the value "No name supplied" if the user fails to enter a guest name. Use the data from the TextField object to update the Reservation object.
Use a TextField to enable the user to enter the number of nights for the reservation. The number of nights must be numeric and greater than zero. Use 1 as the default if the number of nights entered by the user is not valid. Update the TextField in the user interface with the value 1 if the user enters an invalid number. Use the data from the TextField object to update the Reservation object.
Use a ComboBox for the type of room. Call the static method getAllRoomTypes in the Reservation class to get a String array containing the type of rooms. Use this String array to populate the ComboBox . Use the data from the ComboBox to update the Reservation object.
Use a CheckBox for the breakfast option. This option should NOT be selected when the application starts. Use the public constant from the Reservation class to display the amount for the breakfast option. Use the data from the CheckBox object to update the Reservation object.
Use a CheckBox for the smoking room option. This option should NOT be selected when the application starts. Use the public constant from the Reservation class to display the amount for the smoking room. Use the data from CheckBox object to update the Reservation object.
You will need two event handlers - one for the Reserve button and one for the Exit button.
Do not use an "automatic" layout tool like that in NetBeans or Eclipse. Code your user interface from scratch.
Use this version of the Reservation class:
public class Reservation {
public static final int BUDGET_ROOM = 0;
public static final int BUSINESS_ROOM = 1;
public static final int DELUXE_ROOM = 2;
public static final double BUDGET_ROOM_RATE = 100;
public static final double BUSINESS_ROOM_RATE = 150;
public static final double DELUXE_ROOM_RATE = 300;
public static final double BREAKFAST_PKG_RATE = 7;
public static final double SMOKING_RATE = 5;
private int roomType;
private int numOfNights;
private String guestName;
private boolean isSmokingRoom;
private boolean isBreakfastPackage;
public Reservation() {
//Use default values for all data members except name and
# of nights:
this(0, "No name for guest", 1, false, false);
}
public Reservation(int roomType,
String guestName,
int numOfNights,
boolean isSmokingRoom,
boolean isBreakfastPackage) {
setRoomType(roomType);
setSmokingRoom(isSmokingRoom);
setNumOfNights(numOfNights);
setGuestName(guestName);
setBreakfastPackage(isBreakfastPackage);
}
/*
* Calculation for total cost of reservation is:
* (room rate + breakfast plan rate +
* smoking surcharge) * number of nights
*/
public double getAmountDue(){
double rate = 0;
if (this.roomType == BUDGET_ROOM)
rate = BUDGET_ROOM_RATE;
else
if (this.roomType == BUSINESS_ROOM)
rate = BUSINESS_ROOM_RATE;
else {
rate = DELUXE_ROOM_RATE;
}
double amount = rate * this.numOfNights;
if (this.isBreakfastPackage)
amount += BREAKFAST_PKG_RATE *
this.numOfNights;
if (this.isSmokingRoom)
amount += SMOKING_RATE * this.numOfNights;
return amount;
}
public int getRoomType() {
return roomType;
}
/*
* This method returns all the room types available in the form
* of an array of String objects. Each element in the array
* contains the name for the type of room and that room's
* nightly charge. Because the method is static it can be called
* without creating an object of the Reservation class.
*/
public static String[] getAllRoomTypes(){
String [] userFriendlyRoomTypes = new String[3];
userFriendlyRoomTypes[0] = "Budget ($100ight)";
userFriendlyRoomTypes[1] = "Business ($150ight)";
userFriendlyRoomTypes[2] = "Deluxe ($300ight)";
return userFriendlyRoomTypes;
}
public void setRoomType(int newRoomType) {
if (newRoomType >= BUDGET_ROOM && newRoomType
DELUXE_ROOM){
this.roomType = newRoomType;
} else {
throw new IllegalArgumentException("Illegal
room type. Received: " + newRoomType);
}
}
public boolean isSmokingRoom() {
return isSmokingRoom;
}
public void setSmokingRoom(boolean isSmokingRoom) {
this.isSmokingRoom = isSmokingRoom;
}
public int getNumOfNights() {
return numOfNights;
}
public void setNumOfNights(int newNumOfNights) {
if (newNumOfNights > 0){
this.numOfNights = newNumOfNights;
} else {
throw new IllegalArgumentException("Illegal
number of nights. Must be > 0. Received: " + newNumOfNights);
}
}
public String getGuestName() {
return guestName;
}
public void setGuestName(String newGuestName) {
if (newGuestName != null && newGuestName.length() > 0) {
this.guestName =
newGuestName;
} else {
throw new IllegalArgumentException("Illegal
guest name. Can't be null or 0 length.");
}
}
public boolean isBreakfastPackage() {
return isBreakfastPackage;
}
public void setBreakfastPackage(boolean isBreakfastPackage) {
this.isBreakfastPackage = isBreakfastPackage;
}
@Override
public String toString() {
return "Reservation [roomType=" + roomType + ",
isSmokingRoom=" + isSmokingRoom + ", numOfNights=" + numOfNights
+ ", guestName=" + guestName + ",
isBreakfastPackage=" + isBreakfastPackage + "]";
}
}
Do not make any changes to this class.This class can throw IllegalArgumentException exceptions. This is an unchecked exception from the Java APIs. That is why there is no separate IllegalArgumentException class for you to download.
Reser... - X Name Number of Nights Room Type Budget ($100ight) Breakfast Pkg? ($7.00 per day) Smoking Room? ($5.00 per day) Total amount owed: $0.00 ReserveExitStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
