Question
HotelCheckOut.java: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class HotelCheckOut extends JApplet implements ActionListener { private final double PRICE_SUITE = 499.00; private final double PRICE_DOUBLE
HotelCheckOut.java:
import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class HotelCheckOut extends JApplet implements ActionListener { private final double PRICE_SUITE = 499.00; private final double PRICE_DOUBLE = 159.00; private final double PRICE_SINGLE = 99.00; private JLabel name1, name2, room, quantity, days, currency, exchange, display, result; private JPanel mainpanel, leftpanel, rightpanel; private JTextField numSuite, numDoubleRoom, numSingleRoom, numDays, exchangeRate; private JCheckBox suite, doubleRoom, singleRoom; private JRadioButton usCurrency, cdnCurrency; private JButton calculate; private ButtonGroup group;
public void init() { // Set JApplet dimension setSize(400, 350); mainpanel = new JPanel(); leftpanel = new JPanel(); rightpanel = new JPanel(); name1 = new JLabel(" OKANAGAN"); name2 = new JLabel("HOTEL"); room = new JLabel("Room Type:"); quantity = new JLabel("Number of rooms:"); days = new JLabel("Number of days:"); currency = new JLabel("Currency for Payment:"); exchange = new JLabel("U.S. Exchange Rate:"); suite = new JCheckBox("Suite"); doubleRoom = new JCheckBox("Double Room"); singleRoom = new JCheckBox("Single Room"); usCurrency = new JRadioButton("U.S. Currency"); cdnCurrency = new JRadioButton("Cdn Currency", true); numSuite = new JTextField("0"); numDoubleRoom = new JTextField("0"); numSingleRoom = new JTextField("0"); numDays = new JTextField("1"); exchangeRate = new JTextField(""); calculate = new JButton("Check Out"); display = new JLabel("Total amount:"); result = new JLabel(" "); result.setBorder(BorderFactory.createEtchedBorder()); group = new ButtonGroup(); group.add(usCurrency); group.add(cdnCurrency); exchangeRate.setEditable(false); calculate.addActionListener(this); usCurrency.addActionListener(this); cdnCurrency.addActionListener(this); mainpanel.setLayout(new GridLayout(1, 2)); leftpanel.setLayout(new BoxLayout(leftpanel, BoxLayout.Y_AXIS)); rightpanel.setLayout(new BoxLayout(rightpanel, BoxLayout.Y_AXIS)); leftpanel.add(name1); leftpanel.add(Box.createRigidArea(new Dimension(0, 21))); leftpanel.add(room); leftpanel.add(Box.createRigidArea(new Dimension(0, 9))); leftpanel.add(suite); leftpanel.add(Box.createRigidArea(new Dimension(0, 8))); leftpanel.add(doubleRoom); leftpanel.add(Box.createRigidArea(new Dimension(0, 8))); leftpanel.add(singleRoom); leftpanel.add(Box.createRigidArea(new Dimension(0, 15))); leftpanel.add(days); leftpanel.add(Box.createRigidArea(new Dimension(0, 15))); leftpanel.add(currency); leftpanel.add(usCurrency); leftpanel.add(cdnCurrency); leftpanel.add(Box.createRigidArea(new Dimension(0, 18))); leftpanel.add(display); rightpanel.add(name2); rightpanel.add(Box.createRigidArea(new Dimension(0, 22))); rightpanel.add(quantity); rightpanel.add(Box.createRigidArea(new Dimension(0, 11))); rightpanel.add(numSuite); rightpanel.add(Box.createRigidArea(new Dimension(0, 10))); rightpanel.add(numDoubleRoom); rightpanel.add(Box.createRigidArea(new Dimension(0, 10))); rightpanel.add(numSingleRoom); rightpanel.add(Box.createRigidArea(new Dimension(0, 15))); rightpanel.add(numDays); rightpanel.add(Box.createRigidArea(new Dimension(0, 15))); rightpanel.add(exchange); rightpanel.add(Box.createRigidArea(new Dimension(0, 6))); rightpanel.add(exchangeRate); rightpanel.add(Box.createRigidArea(new Dimension(0, 40))); rightpanel.add(result); rightpanel.add(Box.createRigidArea(new Dimension(0, 15))); rightpanel.add(calculate); mainpanel.add(leftpanel); mainpanel.add(rightpanel); add(mainpanel); } // init
public void computePayment() { String msg = "";
try { // Total payment double payment = 0;
// Get total price of suite if (suite.isSelected()) { msg = "Invalid number of Suites"; payment += Integer.parseInt(numSuite.getText().trim()) * PRICE_SUITE; }
// Get total price of double room if (doubleRoom.isSelected()) { msg = "Invalid number of Double Rooms"; payment += Integer.parseInt(numDoubleRoom.getText().trim()) * PRICE_DOUBLE; }
// Get total price of single room if (singleRoom.isSelected()) { msg = "Invalid number of Single Rooms"; payment += Integer.parseInt(numSingleRoom.getText().trim()) * PRICE_SINGLE; }
// Get number of days msg = "Invalid number of days"; int ttlDays = Integer.parseInt(numDays.getText().trim());
// Update payment payment *= ttlDays;
// Check currency for payment if (usCurrency.isSelected()) { msg = "Invalid exchange rate";
// Get exchange rate payment /= Double.parseDouble(exchangeRate.getText().trim());
// Set payment on result label result.setText(String.format("USD %.2f", payment)); } else // Set payment on result label result.setText(String.format("CAD %.2f", payment));
} catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(this, msg, "Error!!!", JOptionPane.ERROR_MESSAGE, null); } }
public void actionPerformed(ActionEvent event) { // Get source button Object src = event.getSource();
if (src == calculate) // Calculate button is clicked computePayment(); else if (src == usCurrency) // Payment in USD // Enable exchangeRate textfield exchangeRate.setEditable(true); else if (src == cdnCurrency) { // Payment in CAD // Disable exchangeRate textfield exchangeRate.setEditable(false);
// Compute payment computePayment(); }
} // actionPerformed } // class HotelCheckOut
b) 135%) Copy your completed HotelCheckOujava file from part (a) and name it as HotelCheckOutb.java. Then you modify the HotelCheckOutb applet program file further by providing additional features like mnemonic, TipToolText and input controls with exception handling. Check below to see how your finished applet should work: OKANAGAN HOTEL OKANAGAN HOTEL Room Type: Number of rooms: Room Type: Number of rooms: Suite 2.1 Suite Double Room Double Room Single Room Number of days: Single Room 2 Number of days: 2.5 Currency for Payment: U.S. Exchange Rate: us. currency Currency for Payment: U.S. Exchange Rate: U.S. Currency Cdn Currency Cdn Currency Total amount: Input errors: Only integers allowed for the numbers of rooms and days , CON $1,316.00 Gleck Outal.com an s Check Out Total amount: Input errors: Only integers allowed for the numbers $0 b) 135%) Copy your completed HotelCheckOujava file from part (a) and name it as HotelCheckOutb.java. Then you modify the HotelCheckOutb applet program file further by providing additional features like mnemonic, TipToolText and input controls with exception handling. Check below to see how your finished applet should work: OKANAGAN HOTEL OKANAGAN HOTEL Room Type: Number of rooms: Room Type: Number of rooms: Suite 2.1 Suite Double Room Double Room Single Room Number of days: Single Room 2 Number of days: 2.5 Currency for Payment: U.S. Exchange Rate: us. currency Currency for Payment: U.S. Exchange Rate: U.S. Currency Cdn Currency Cdn Currency Total amount: Input errors: Only integers allowed for the numbers of rooms and days , CON $1,316.00 Gleck Outal.com an s Check Out Total amount: Input errors: Only integers allowed for the numbers $0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started