Write an application for Lambert\'s Vacation Rentals. Use separate ButtonGroups
ID: 3557528 • Letter: W
Question
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 prices. Assume that if meals are added, the price is $200 more per rental.
Language: Java
Explanation / Answer
public class Lambert extends JFrame
{
int Parksideroom1 = 0;
int Poolsideroom2 = 0;
int Lakesideroom2 = 0;
int weeks;
int boat = 0;
JPanel p, p1;
JLabel l, l1;
JTextField t, t1;
JButton b;
JCheckBox b1, b2, b3;
Lambert()
{
setTitle("Room Selection");
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(p);
setVisible(true);
}
void buildPanel()
{
l = new JLabel("Select a room type");
l1 = new JLabel("How many weeks will you be staying?");
b = new JButton("Confirm");
b1 = new JCheckBox("1 bedroom parkside($600 per week)");
b2 = new JCheckBox("2 Bedroom poolside($750 per week)");
b3 = new JCheckBox("2 Bedroom lakeside($825 per week)");
b4 = new JCheckBox("meals rental ($200 per week)");
p = new JPanel();
p1 = new JPanel();
add(p);
p.add(l);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(l1);
p.add(b);
add(p1);
b.addActionListener(new buttonlistener());
b1.addItemListener(new cbListener());
b2.addItemListener(new cbListener());
b3.addItemListener(new cbListener());
b4.addItemListener(new cbListener());
setVisible(true);
}
class buttonlistener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String i = t.getText();
int val = Integer.parseInt(i);
val = (Parksideroom1 + Poolsideroom2 + Lakesideroom2 + meals) * weeks;
JOptionPane.showMessageDialog(null, "Total is " + val);
}
}
class cbListener implements ItemListener
{
public void itemStateChanged(ItemEvent b)
{
if (b.getSource() == b1)
{
if (b1.isSelected())
{
Parksideroom1 = 600;
}
if (b.getSource() == b3)
{
if (b3.isSelected())
{
meals = 200;
}
}
}
else if (b.getSource() == b2)
{
if (b2.isSelected())
{
Poolsideroom2 = 750;
}
if (b.getSource() == b3)
{
if (b3.isSelected())
{
meals = 200;
}
}
}
else if (b.getSource() == b2)
{
if (b3.isSelected())
{
Lakesideroom2 = 825;
}
if (b.getSource() == b4)
{
if (b4.isSelected())
{
meals = 200;
}
}
}
}
}
public static void main(String[] args)
{
Lambert a1 = new Lambert();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.