Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please do not answer this question with an offer to do the answer in exchange fo

ID: 3539777 • Letter: P

Question

Please do not answer this question with an offer to do the answer in exchange for paypal payment.


Please DO BOTH PARTS (PART A & PART B) in order to get FULL 3000 points.


PART A)


Create an interactive applet which allows the user to run a simplified hotel check-out program.


You%u2019ll find that all the GUI components required by this applet program have already added in appropriate places in the HotelCheckOut.java file. All you need to do is to complete the program for the calculation of the total accommodation charges when a customer checks out from the hotel.


// File: HotelCheckOut.java



import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.text.DecimalFormat;


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() {

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() {

// complete this method for the payment.



}


public void actionPerformed (ActionEvent event) {

// complete this method to perform appropriate actions



} // actionPerformed


} // class HotelCheckOut


Here are some specifications to guide your work:


ANSWER BOTH PARTS TO ATTAIN FULL 3000 POINTS ALONG WITH 5 STARS.





Explanation / Answer

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.text.DecimalFormat;

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;
    private double total = 0.0;

    public void init() {

        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");

       calculate
                .setToolTipText("Click on the button to compute the total amount");

        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(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                exchangeRate.setEditable(true);

            }
        });

        cdnCurrency.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                exchangeRate.setText("");
                exchangeRate.setEditable(false);

            }
        });

        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);
        setSize(600, 350);

    } // init

    public void computePayment() {

        try {

           
            int numSuits = Integer.parseInt(numSuite.getText());
            int numDoubleRooms = Integer.parseInt(numDoubleRoom.getText());
            int numSingleRooms = Integer.parseInt(numSingleRoom.getText());
            int numDayz = Integer.parseInt(numDays.getText());
            total = numDayz
                    * (numSuits * PRICE_SUITE + numDoubleRooms * PRICE_DOUBLE + numSingleRooms
                            * PRICE_SINGLE);
            double exchangeRt = 1;
            if (exchangeRate.isEditable()) {
                exchangeRt = Double.parseDouble(exchangeRate.getText());
            }
            total = exchangeRt * total;
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(this, "Invalid Input (Not a number)");
        }
        // complete this method for the payment.

    }

    public void actionPerformed(ActionEvent event) {

        computePayment();
        result.setText("" + total);
        // complete this method to perform appropriate actions

    } // actionPerformed

} // class HotelCheckOut