Question

In Java: Create a GUI application that calculates the registration fees for a one-week summer camp....

In Java: Create a GUI application that calculates the registration fees for a one-week summer camp. The general summer camp registration fee is $895 per person, but multiple children from the same family (after the first) are allowed a $200 discount. There is a lavish closing banquet, with awards for their children, which parents may attend for $25 (each). As many other optional pre- and post-activity sessions may be added (for indicated fee), thanks to scheduling them in exclusive time slots:

  • Introduction to Horsemanship        $295
  • Beginning Swimming                      145
  • Advanced Archery                           115
  • Mountain Biking on Steroids           245

The application should allow the user to select the registration type (e.g., first or multiple child), optional parent(s) dinner attendance, and as many pre/post-camp sessions as desired. The camper’s name should be requested during registration and displayed along with their chosen itinerary and total registration cost.

add surnames

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program in java:

//importing required classes
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

//class definition
public class SummerCampGUI extends JFrame implements ActionListener,ItemListener{
    //variables
    JLabel lb1,lb2,lb3,lb4;
    JCheckBox cb1,cb2,cb3,cb4,cb5,cb6;
    JComboBox c1;
    JTextField tf1,tf2;
    JTextArea ta;
    JButton btn;
  
    //constructor
    public SummerCampGUI() {
        //intiallization
        lb1=new JLabel("Name");
        lb2=new JLabel("Surname");
        lb3=new JLabel("Registration type");
        lb4=new JLabel("Registration fees $895");
        tf1=new JTextField();
        tf2=new JTextField();
        ta=new JTextArea();
        String type[]={"Single","Multiple"};
        c1=new JComboBox(type);
        c1.addItemListener(this);
        cb1=new JCheckBox("Parents dinner           $25");
        cb2=new JCheckBox("Introduction to Horsemanship         $295");
        cb3=new JCheckBox("Beginning Swimming                   $145");
        cb4=new JCheckBox("Advanced Archery                     $115");
        cb5=new JCheckBox("Mountain Biking on Steroids          $245");
        btn=new JButton("Submit");
        btn.addActionListener(this);
      
        //specifying the component position
        setLayout(null);
        lb1.setBounds(50,50,150,20);
        lb2.setBounds(50,80,150,20);
        lb3.setBounds(50,110,150,20);
        c1.setBounds(200,110,150,20);
        tf1.setBounds(200,50,150,20);
        tf2.setBounds(200,80,150,20);
        lb4.setBounds(50,140,300,20);
        cb1.setBounds(50,170,300,20);
        cb2.setBounds(50,200,300,20);
        cb3.setBounds(50,230,300,20);
        cb4.setBounds(50,260,300,20);
        cb5.setBounds(50,290,300,20);
        btn.setBounds(150,320,100,20);
        ta.setBounds(50,350,300,200);
      
        //adding component
        add(lb1);
        add(lb2);
        add(lb3);
        add(c1);
        add(tf1);
        add(tf2);
        add(lb4);
        add(cb1);
        add(cb2);
        add(cb3);
        add(cb4);
        add(cb5);
        add(btn);
        add(ta);
    }
  
    //main method definition
    public static void main(String[] args) {
        //creating instance of class
        SummerCampGUI sc=new SummerCampGUI();
        //defining the size
        sc.setSize(400,600);
        //making the gui visible
        sc.setVisible(true);
        //option on closing the frame
        sc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    //coding the action of the button
    @Override
    public void actionPerformed(ActionEvent ae) {
        int total=0;
        //adding the details in text area
        ta.setText("Itinery details are as follows\n--------------------------------------\n\n");
        ta.append("Name: "+tf1.getText()+" ");
        ta.append(tf2.getText()+"\n");
        if(c1.getSelectedIndex()==1){
            total=total+895;
            ta.append(lb4.getText()+"\n");
        }
        else{
            total=total+695;
            ta.append(lb4.getText()+"\n");
        }
        if(cb1.isSelected()){
            total=total+25;
            ta.append(cb1.getText()+"\n");
        }
        if(cb2.isSelected()){
            total=total+295;
            ta.append(cb2.getText()+"\n");
        }
        if(cb3.isSelected()){
            total=total+145;
            ta.append(cb3.getText()+"\n");
        }
        if(cb4.isSelected()){
            total=total+115;
            ta.append(cb4.getText()+"\n");
        }
        if(cb5.isSelected()){
            total=total+245;
            ta.append(cb5.getText()+"\n");
        }
        ta.append("\nTotal: $"+total);
      
    }

    //coding the checkbox action
    @Override
    public void itemStateChanged(ItemEvent e) {
        String str=e.getItem().toString();
        if(str.equalsIgnoreCase("Single")){
            lb4.setText("Registration fees $895");
        }
        else if(str.equalsIgnoreCase("Multiple")){
            lb4.setText("Registration fees $695 ($200 discount)");
        }
        else{
            JOptionPane.showMessageDialog(this, "Please select registration type");
        }
    }
}

Output:

Add a comment
Know the answer?
Add Answer to:
In Java: Create a GUI application that calculates the registration fees for a one-week summer camp....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT