Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The cost to became a member of a fitness center is as follows: (a) the senior ci

ID: 3659332 • Letter: T

Question

The cost to became a member of a fitness center is as follows: (a) the senior citizens discount is 30%; (b) if the membership is bought and paid for 12 or more months in advance, the discount is 15%; or (c) if more than 5 personal training sessions are purchased, the discount on each session is 20%. write a menu driven program that determines the cost of a new membership. your program must contain a method thats displays the general information about the fitness center and it charges, a method to get all the nesessary information to determine the membership cost, and a method to determine the membership cost. use appropriate parameters to pas information in and out of method.

Explanation / Answer

The Program is given below which has a Graphical user interface. The fee is calculated based on the user selction in the dropdown box

to compile use javac FitnessCenter.java

to run java FitnessCenter

FitnessCenter.java

import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class FitnessCenter {

   
    JFrame frame;
    JTextArea generalInfo;
    JComboBox membershipOptions;
    String info;
    String[] options;
    JTextField amount;
    int fee = 500;
    JLabel optionLabel;
    JLabel feeLabel;
    JLabel heading;
    public FitnessCenter() {
        info = " (a) the senior citizens discount is 30% (option1); " +
                "(b) if the membership is bought and paid for 12 or more months in advance, the discount is 15% (option2); " +
                "(c) if more than 5 personal training sessions are purchased, the discount on each session is 20% (option3)";
        frame = new JFrame("Fitness Center");
        generalInfo = new JTextArea(info);
        options = new String[]{"general", "option1", "option2", "option3"};
        membershipOptions = new JComboBox(options);
        amount = new JTextField();
        amount.setText(fee+"");
        optionLabel = new JLabel("Select an option: ");
        feeLabel = new JLabel("fee to be paid: ");
        heading = new JLabel("Welcome to Fitness Center the original fee is: " + fee + "$");
        Box horizontalBox1 = Box.createHorizontalBox();
        horizontalBox1.add(optionLabel);
        horizontalBox1.add(membershipOptions);
        horizontalBox1.setSize(200,100);
        horizontalBox1.setVisible(true);
       
        Box horizontalBox2 = Box.createHorizontalBox();
        horizontalBox2.add(feeLabel);
        horizontalBox2.add(amount);
        horizontalBox2.setSize(200,50);
        horizontalBox2.setVisible(true);
       
        Box verticalBox = Box.createVerticalBox();
        verticalBox.setAlignmentY(Box.TOP_ALIGNMENT);
        //verticalBox.add(heading);
        verticalBox.add(generalInfo);
        verticalBox.add(horizontalBox1);
        verticalBox.add(horizontalBox2);
       
        //frame.setLayout(new FlowLayout());
        verticalBox.setSize(400,200);
        verticalBox.setVisible(true);
        frame.add(heading);
        frame.add(verticalBox);
        frame.setSize(500,300);
        frame.setLayout(new FlowLayout(FlowLayout.LEFT));
        frame.setVisible(true);
        membershipOptions.addItemListener(new ItemListener() {
           
            @Override
            public void itemStateChanged(ItemEvent arg0) {
                // TODO Auto-generated method stub
                String selectedOption = arg0.getItem().toString();
                int feeAfterDiscount = fee;
                if(selectedOption.equals("option1"))
                    feeAfterDiscount = fee - ((fee*30)/100);
                else if(selectedOption.equals("option2"))
                    feeAfterDiscount = fee - ((fee*15)/100);
                else if(selectedOption.equals("option3"))
                    feeAfterDiscount = fee - ((fee*20)/100);
                amount.setText(feeAfterDiscount+"");
            }
        });
    }
    /**
    * @param args
    */
    public static void main(String[] args) {

        new FitnessCenter();
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote