Create an application for Disney\'s Cottages, a weekend getaway resort that rent
ID: 666352 • Letter: C
Question
Create an application for Disney's Cottages, a weekend getaway resort that rents cottages and boats to use on the local lake. The application allows users to compute the price of a vacation based on start and end date of a vacation. Include mutually exclusive checkboxes to select a one-bedroom cottage at $600.00 per week or a two bedroom cottage at $850.00 per week. The user also can choose a rowboat rental at $60.00 per week. Include labels as appropriate toe explain the application's functionality. Save file as DisneyCottage.java.
Explanation / Answer
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
class DisneyCottage extends JFrame
{
JRadioButton b1, b2;
JPanel p1;
JLabel l;
JTextField t1, t2;
JButton b;
Checkbox b3;
DisneyCottage()
{
setTitle("Vacation Package");
setSize(300,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(b3);
032
p1 = new JPanel();
033
034
035
add(p1);
setVisible(true);
}
void buildPanel()
{
b1 = new JRadioButton("One Bedroom");
b2 = new JRadioButton("Two Bedroom", true);
b3 = new Checkbox("Rowboat");
ButtonGroup g = new ButtonGroup();
g.add(b1);
g.add(b2);
l = new JLabel("Time Frame");
t1 = new JTextField("Start Date YYYYMMDD");
t2 = new JTextField("End Date YYYYMMDD");
b = new JButton("Compute");
b.addActionListener(new buttonlistener());
p1.add(l);
p1.add(t1);
p1.add(t2);
p1.add(b);
b1.addActionListener(new b1Listener());
b2.addActionListener(new b1Listener());
b3.addItemListener(new cbListener());
p1.add(b1);
p1.add(b2);
p1.add(b3);
}
class buttonlistener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
String dt1 = t1.getText();
String dt2 = t2.getText();
Date date1, date2;
}
}
class b1Listener implements ActionListener
{
public void actionPerformed(ActionEvent b)
{
if (b.getActionCommand().equals("b1"))
{
long subtotal = (diff/7) * 600;
}
else
{
long subtotal = (diff/7) * 850;
}
}
}
class cbListener implements ItemListener
{
public void itemStateChanged(ItemEvent b)
{
if (b3.isSelected())
{
long total = subtotal + 60 * (diff/7);
JOptionPane.showMessageDialog(null, "Your price is" + subtotal);
}
else
{
long total = subtotal;
JOptionPane.showMessageDialog(null, "Your price is" + subtotal);
}
}
}
public static void main(String [] args)
{
DisneyCottage a1 = new DisneyCottage();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.