In: Computer Science
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.
// 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: