Question

In: Computer Science

Write an application for Lambert’s Vacation Rentals. Use separate ButtonGroups to allow a client to select...

Write an application for Lambert’s Vacation Rentals. Use separate ButtonGroups to allow a client to select one of three locations, the number of bedrooms, and whether meals are included in the rental. Assume that the locations are parkside for $600 per week, poolside for $750 per week, or lakeside for $825 per week. Assume that the rentals have one, two, or three bedrooms and that each bedroom over one adds $75 to the base price. Assume that if meals are added, the price is $200 more per rental. Save the file as JVacationRental.java.

This is also the 3rd time im gonna post it since all the answers im getting has a lot of errors so please help me

Solutions

Expert Solution

JVacationRental.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JVacationRental extends JFrame implements ItemListener
{
   //declare variables
   final static int SIZE = 300;
   FlowLayout flow = new FlowLayout();
   String companyName = new String("Lambert's Vacation Rentals");
   Font font = new Font("Arial", Font.PLAIN, 24);
   final int PARK_PRICE = 600, POOL_PRICE = 750, LAKE_PRICE = 825;
   int totalPrice = 0;

   //declare location button group and all buttons
   ButtonGroup locationGroup = new ButtonGroup();
   JCheckBox parkBox = new JCheckBox("Parkside", false);
   JCheckBox poolBox = new JCheckBox("Poolside", false);
   JCheckBox lakeBox = new JCheckBox("Lakeside", false);

   //declare bedroom button group and all buttons
   final int ONE_PRICE = 0, TWO_PRICE = 75, THREE_PRICE = 150;
   ButtonGroup bedGroup = new ButtonGroup();
   JCheckBox oneBox = new JCheckBox("1 bedroom", false);
   JCheckBox twoBox = new JCheckBox("2 bedrooms", false);
   JCheckBox threeBox = new JCheckBox("3 bedrooms", false);

   //declare meals button group and all butttons
   final int NO_MEAL_PRICE = 0, MEAL_PRICE = 200;
   ButtonGroup mealGroup = new ButtonGroup();
   JCheckBox noMealsBox = new JCheckBox("No meals", false);
   JCheckBox mealsBox = new JCheckBox("Meals", false);

   JTextField totPrice = new JTextField(10);
   String output;

   //constructor sets all frame attributes and adds swing components to frame
   public JVacationRental()
   {
       super("Vacation Rentals");
       setSize(SIZE,SIZE);
       setVisible(true);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLayout(flow);
       locationGroup.add(parkBox);
       parkBox.addItemListener(this);
       locationGroup.add(poolBox);
       poolBox.addItemListener(this);
       locationGroup.add(lakeBox);
       lakeBox.addItemListener(this);

       add(parkBox);
       add(poolBox);
       add(lakeBox);

       bedGroup.add(oneBox);
       oneBox.addItemListener(this);
       bedGroup.add(twoBox);
       twoBox.addItemListener(this);
       bedGroup.add(threeBox);
       threeBox.addItemListener(this);

       add(oneBox);
       add(twoBox);
       add(threeBox);

       mealGroup.add(noMealsBox);
       noMealsBox.addItemListener(this);
       mealGroup.add(mealsBox);
       mealsBox.addItemListener(this);

       add(noMealsBox);
       add(mealsBox);

       add(totPrice);
       totPrice.setText("0.00");


   }

   //event handler method
   public void itemStateChanged(ItemEvent check)
   {
       //get source
       Object source = check.getItem();

       //parkBox had been clicked
       if(source == parkBox)
       {
           int select = check.getStateChange();
           //parkBox is selected
           if(select == ItemEvent.SELECTED)
           {
               //add the park price to total price
               totalPrice += PARK_PRICE;
           }
           else
           {
               //parkBox has been deselected
               if(select == ItemEvent.DESELECTED)
               {
                   //subtract park price from total price
                   totalPrice -= PARK_PRICE;
               }
           }

           //update totalPrice and output it to frame
           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //poolside
       if(source == poolBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += POOL_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= POOL_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //lakeside
       if(source == lakeBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += LAKE_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= LAKE_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //one bedroom
       if(source == oneBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += ONE_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= ONE_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //two bedrooms
       if(source == twoBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += TWO_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= TWO_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //three bedrooms
       if(source == threeBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += THREE_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= THREE_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //no meals
       if(source == noMealsBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += NO_MEAL_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= NO_MEAL_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

       //meals
       if(source == mealsBox)
       {
           int select = check.getStateChange();
           if(select == ItemEvent.SELECTED)
           {
               totalPrice += MEAL_PRICE;
           }
           else
           {
               if(select == ItemEvent.DESELECTED)
               {
                   totalPrice -= MEAL_PRICE;
               }
           }

           output = "" + totalPrice;
           totPrice.setText(output);
       }

   }

   public static void main(String[] args)
   {
       JVacationRental vacationFrame = new JVacationRental();


   }
}

Output:-


Related Solutions

Implement and test a TaskList application in Java that will allow a client to manage information...
Implement and test a TaskList application in Java that will allow a client to manage information about daily tasks.  A task has a task name, is scheduled on a specific day of the week and can have a comment attached to it. Together, the task name and day uniquely identify a task. There may be tasks with the same name scheduled for different days of the week. The application should allow the client to start with an empty TaskList and then...
Question 2: Write a Java console application that will allow a user to add contacts to...
Question 2: Write a Java console application that will allow a user to add contacts to a contact list and view their current contact list sorted alphabetically. Your program should prompt the user to select an action (add or view). If the user chooses to add a contact, the contact information should be entered using the following format: Firstname Lastname, PhoneNumber If the user chooses to view their contact list, your program should display each contact on a separate line...
Instructions Write a Client/Server application to do the following​ Client​ Take in IP address and Port...
Instructions Write a Client/Server application to do the following​ Client​ Take in IP address and Port as command line arguments​ Connect to Server​ Start "infinite loop"​ Take in message from command line​ Convert it to the packet form from last lab​ Instead of an array, store packet in a char array (string) so it can be easily sent​ Print out packet to terminal​ Send packet to server​ Print out reply from server End "infinite loop" Server Create connection on the...
Instructions Write a Client/Server application to do the following​ Client​ Take in IP address and Port...
Instructions Write a Client/Server application to do the following​ Client​ Take in IP address and Port as command line arguments​ Connect to Server​ Start "infinite loop"​ Take in message from command line​ Convert it to the packet form from last lab​ Instead of an array, store packet in a char array (string) so it can be easily sent​ Print out packet to terminal​ Send packet to server​ Print out reply from server End "infinite loop" Server Create connection on the...
Write and test a user-defined class (requiring conditions). Write an application (client) program that uses an...
Write and test a user-defined class (requiring conditions). Write an application (client) program that uses an instance(s) of a user-defined class. The federal income tax that a person pays is a function of the person's taxable income. The following table contains formulas for computing a single person's tax. Bracket Taxable Income Tax Paid 1 $22,100 or less 15% 2 More than $22,100 but $53,500 or less $3,315 plus 28% of the taxable income over $22,100 3 More than $53,500 but...
The arrival of Airbnb to Malaysia has make changes on the short-term vacation rentals, which should...
The arrival of Airbnb to Malaysia has make changes on the short-term vacation rentals, which should be better for Malaysia, and/or is Airbnb killing the Hospitality industry or will eventually kill the industry? Discuss the solutions or recommendations to benefit both Airbnb and Tourism industry in Malaysia
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
Write a Python Client/Server Socket Program that will allow you to send text messages between the...
Write a Python Client/Server Socket Program that will allow you to send text messages between the server and client, terminating when the exit is typed on the client. Build the program on your 2-VM’s and get it working. Cut and paste your code below along with screen shots of your program working.
Write a program to allow a user to play the game Hangman. DO NOT USE AN...
Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess. Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the...
Comparing beach vacation to a mountain vacation. Write a paragraph 150 to 200 words.
Comparing beach vacation to a mountain vacation. Write a paragraph 150 to 200 words.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT