Question

In: Computer Science

IN JAVA(NETBEANS) PLEASE: The cost to become a member of a fitness center is as follows:...

IN JAVA(NETBEANS) PLEASE:

The cost to become 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 that displays the general information about the fitness center and its charges, a method to get all the necessary information to determine the membership cost, and a method to determine the membership cost. Use appropriate parameters to pass information in and out of a method. Implement the program as specified below: METHOD displayGeneralInformation - displays all of the costs and asks for the age Welcome to Fitness Center Service Costs 3 month membership $350 6 month membership $600 Java Programming: From Problem Analysis to Program Design 7-2 1 year membership $1000 (15% discount if paid in full) Personal training sessions $80/hour for each session (20% discount on each session if more than 5 sessions are purchased) ***If you are 55 years or older, you will receive a 30% discount Please enter your age: METHOD getDataMenu - shows the menu and returns the value entered 1. Purchase Membership 2. Purchase Sessions Choose from the Menu: METHOD: getMembershipCost If option 1 from menu above entered: A- 3 month membership $350 B- 6 month membership $600 C- 1 year membership $1000 (15% discount if paid in full) Choose your membership level: METHOD: getTrainingSessionsCost - returns training session cost If option 2 entered: Enter the number of sessions you would like to purchase: METHOD: totalMembershipCost Your total membership cost is: $…… Note: Senior citizens who buy a 12 month membership and pay in full will first receive 30% off the 1,000 and then 15% off the remaining balance. Senior citizens also receive 15% off training sessions. Discussion the 20% off first if more than 5 sessions and then discount the 15% from the balance.

Solutions

Expert Solution

// Java program to calculate the membership cost for a fitness center

import java.util.Scanner;

public class FitnessCenterMembership {

       // method to display general information and input and return the ahe of the user

       public static int displayGeneralInformation(Scanner scan)

       {

             int age;

             System.out.println("Welcome to Fitness Center Service Costs");

             System.out.println("\t3 month membership $350");

             System.out.println("\t6 month membership $600");

             System.out.println("\t1 year membership $1000(15% discount if paid in full)");

             System.out.println("Personal training sessions");

             System.out.println("\t$80/hour for each session (20% discount on each session if more than 5 sessions are purchased)");

             System.out.println("\n***If you are 55 years or older, you will receive a 30% discount");

             System.out.print("\nPlease enter your age: ");

             age = scan.nextInt();

             scan.nextLine();

             return age;

       }

      

       // method to provide menu and input and return user's choice

       public static int getDataMenu(Scanner scan)

       {

             int choice;

             System.out.println("1. Purchase Membership");

             System.out.println("2. Purchase Sessions");

             System.out.print("Choose from the Menu: ");

             choice = scan.nextInt();

             scan.nextLine();

            

             return choice;

       }

      

       // method to input and return the cost of membership based on user's choice

       public static double getMembershipCost(Scanner scan)

       {

             String choice;

             System.out.println("A- 3 month membership $350\nB- 6 month membership $600\nC- 1 year membership $1000 (15% discount if paid in full)");

             System.out.print("Choose your membership level: ");

             choice = scan.nextLine();

            

             if(choice.equalsIgnoreCase("A"))

                    return 350;

             else if(choice.equalsIgnoreCase("B"))

                    return 600;

             else

                    return 1000;

       }

      

       // method to input and return the number of sessions

       public static int getTrainingSessionsCost(Scanner scan)

       {

             int sessions;

             System.out.print("Enter the number of sessions you would like to purchase: ");

             sessions = scan.nextInt();

             scan.nextLine();

            

             return sessions;

       }

      

       // method to calculate and return teh total membership cost

       public static double totalMembershipCost(int age, double membershipCost, int sessions)

       {

             double totalCost = 0;

            

             if(age >=55 )

             {

                    totalCost = membershipCost - (membershipCost*.30);

                    totalCost -= totalCost*.15;

                    double sessionsCost = sessions*80;

                    sessionsCost -= sessionsCost*.20;

                    if(sessions > 5)

                           sessionsCost -= sessionsCost*.15;

                    totalCost += sessionsCost;

             }else

             {

                    totalCost = membershipCost - (membershipCost*.15);

                    double sessionsCost = sessions*80;

                    if(sessions > 5)

                           sessionsCost -= sessionsCost*.15;

                    totalCost += sessionsCost;

             }

            

             return totalCost;

       }

       public static void main(String[] args) {

             Scanner scan = new Scanner(System.in);

             int age = displayGeneralInformation(scan);

            

             int choice, sessions=0;

             double membershipCost = 0;

            

             // loop that continues till the user selects both the membership type and number of sessions

             while(membershipCost == 0 || sessions == 0)

             {

                    choice = getDataMenu(scan);

                    if(choice == 1)

                           membershipCost = getMembershipCost(scan);

                    else if(choice == 2)

                           sessions = getTrainingSessionsCost(scan);

                    else

                           System.out.println("Invalid choice. Select the membership type and number of sessions to calculate the total membership cost");

             }

            

             // display the total membership cost

             System.out.printf("Total membership cost : $%.2f",totalMembershipCost(age,membershipCost,sessions));

             scan.close();

       }

}

//end of program

Output:


Related Solutions

C Code The cost to become a member of a fitness center is as follows: (a)...
C Code The cost to become 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, the discount is 15% (c) if more than five personal training sessions are bought and paid for, the discount on each session is 20% Write a that determines the cost of a new membership. Your program must contain: a function that displays the general information...
(IN C LANGUAGE) The cost to become a member of a fitness center is as follows:...
(IN C LANGUAGE) The cost to become 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, the discount is 15% (c) if more than five personal training sessions are bought and paid for, the discount on each session is 20% Write a that determines the cost of a new membership. Your program must contain: a function that displays the general...
You are hired to design a database for a fitness center. As the fitness center is...
You are hired to design a database for a fitness center. As the fitness center is expanding with more than one branch, they want to create a database to keep track of its customers, facilities and employees. Each branch has a unique id and address (building number, street, district, and city). A branch may have more than one facility (e.g. swimming pool, spa, etc.). Each facility must belong to only one branch, and the information for a facility is name...
You are hired to design a database for a fitness center. As the fitness center is...
You are hired to design a database for a fitness center. As the fitness center is expanding with more than one branch, they want to create a database to keep track of its customers, facilities and employees. Each branch has a unique id and address (building number, street, district, and city). A branch may have more than one facility (e.g. swimming pool, spa, etc.). Each facility must belong to only one branch, and the information for a facility is name...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read and follow the instructions below, placing the code statements needed just after each instruction. Leave the instructions as given in the code. Declare and create (instantiate) an integer array called List1 that holds 10 places that have the values: 1,3,4,5,2,6,8,9,2,7. Declare and create (instantiate) integer arrays List2 and List3 that can hold 10 values. Write a method called toDisplay which will display the contents...
Language: Java(Netbeans) Implement a simple calculator.
Language: Java(Netbeans) Implement a simple calculator.
Steps to making your Netbeans IDE (Interactive Development Environment): Download and install Netbeans 8.2 IDE (Java...
Steps to making your Netbeans IDE (Interactive Development Environment): Download and install Netbeans 8.2 IDE (Java SE version only). If you do not have the latest Java installation to match, Netbeans will direct you to download the needed version of Java. If needed, download and install the latest Oracle Official Java Software Development Kit Standard Edition (Java SDK SE), and JUnit. I suggest you do this via the bundle referred to as The Java Development Kit (JDK). Download the architecture...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
Part A Java netbeans ☑ Create a project and in it a class with a main....
Part A Java netbeans ☑ Create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class , after the package statement, paste import java.util.Scanner; As the first line inside your main method, paste Scanner scan = new Scanner(System.in); Remember when you are getting a value from the user, first print a request, then use the Scanner to read the right type...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT