In: Computer Science
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
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:-
