LAB EXERCISE 15: Membership Fee
In this exercise, you will learn how to:
1. Insert the Main Method (Main Entry Point to the Java Program)
2 Import a Java Class Library
3. Declare Variables and Initialize
4. Create a Constructor (Special Method)
5. Use a Try-Catch block statement for the error handling and exceptions
5. Create Methods with returning values
7. Use the Switch-Case block statement to evaluate a value and execute block of code
8. Use the If-Then-Else-If statement to evaluate conditions and execute code based on the condition
9. Create the Object from the Class
10. Call the Object’s Method and pass arguments to method
Create the LMC Health Club Membership Fee Calculator application. It should allow the user to select the membership type and enter the number of months of the membership. It should calculate the member’s monthly rate, member’s discount if applicable and the total member’s fee with discount. The application should also validate the type of membership and number of months entered by the user. An error message should be display if the user enters an invalid data.
The club charges the following monthly membership rates per type membership:
Type 1 Membership Standard adult: $40/ month
Type 2 Membership- Child (Under agent 12 & under): $20/month
Type 3 Membership- Student $25/ month
Type 4 Membership -Senior citizen $30/ month
Discounts are available depending on the length of membership
1-3 months: No discount
4-6 months 5% discount
7-9 months 8% discount
10 or more months 10% discount
1. Create a folder on your desktop Exercise-15
2. Launch Java EE- Eclipse
Note: You will need to use the Java Perspective Workbench for this exercise
3. Setup your Eclipse Workspace to point to the Exercise-15
a. Select File-> Switch Workspace
b. Browse and select your Exercie-15 folder as your Workspace.
1. Create a Java Project and name it as MemershipFee
2. Create the first Class that will have the Main Method
a. Name the Class as MainApp
b. Choose the main method to insert into the class
3. Create the second Class that will have the Constructor and Method
a. Name the Class as Member
b. Do not select the main method stub
C. Requirements for the Member Class:
1. Insert the import java.util.Scanner class which will allow data to be inputted from the console.
2. Declare the variables typeOfMember and monthMembership using the integer data type.
the variables monthlyRate, totalFee and monthlyDiscount using the
double data type.
4. Create the Constructor called Member () that that will prompt the user to input the data.
the scanner input class objects - Scanner inputData = new Scanner(System.in);
block statement to perform error
handling and exception
1. Prompt the user to input the type of membership
2. Prompt the user to input the number of months of membership
3. Below is the code to the prompt the user for the data
System.out.print("Enter the Type
of Membership (1- Adult, 2- Child 12 & under, 3- Student, 4-Senior
Citizen): " );
3. If the user inputs an invalid date, the code in the Catch block will be executed:
System.out.println("Invalid Membership Type. Member's rate, discount and total fee can not be calculated ");
c. Close the scanner input class object - inputData.close();
5. Create the Method called getMonthlyFeeRate() that will return the monthly rate based on the membership type.
a. Use the Switch statement to test the typeOfMember variable
b. Use the Case statements to check the typeOfMember value and return the monthlyRate value
c. If none of the value matches, set the monthlyRate = 0 as the default
the Method called getDiscount() that will return the monthly
discount based on the number of membership months
NOTE: Use an If-Then-Else-If block statements
the Method called calculateTotalFee() that will return total membership
fee with discount
Accept the membership rate and discount as arguments
D. Requirements for the MainApp Class:
comments (documentation)– Program Description, Author and Date
2. Create the instance of object called fee from the Member class
3. Call the object’s method fee.getMonthlyFeeRate() to get the monthly fee. No arguments passed
Store the returned value to the rate variable with a double data type.
4. Call the object’s method fee.getDiscount() to get the membership fee discount.
No arguments passed
Store the returned value to the discount variable with a double data type.
5. Call the object’s method fee.calculateTotalFee to calculate the total membership fee
Pass the rate and discount as arguments.
Store the returned value to the totalFee variable with a double data type.
6. Display the results on the console. Below is the code:
display the returned results on the console
1. Save your Java code
2. Compile and run your Java program.
3. Verify there is no syntax, logical or run-time errors.
4. Use the following set of test data to determine if the application is running properly
Type of Membership Months Discount Monthly Rate Total Fee
1 5 5% $40.00 $190.00
2 2 0% $20.00 $40.00
3 9 8% $25.00 $207.00
4 10 10% $30.00 $270.00
A Invalid Data
F. Submit your exercise in the Canvas Lab Exercise #15 Drop Box.
1. Submit the screen shot of the Eclipse
Workbench window showing the Console output screen.
You can use Paint (save as JPG) or Word to paste the screenshot.
2. Zip up and submit the compressed MemershipFee subfolder that is in the Exercise-15
NOTE: Right click on the subfolder and select Send to “Compress Folder”. The file will have a file extension of .zip.