Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1: BetterFitness is a membership-based fitness club in Toronto. Customers can purchase a membership that provides a fixed number (e.g. 100) of free

imageimage

image  

Task 1: BetterFitness is a membership-based fitness club in Toronto. Customers can purchase a membership that provides a fixed number (e.g. 100) of free visits to the club upon registration. When the initial number of visits runs out, they can purchase additional visits as needed. All types of fitness equipment and all fitness classes offered in the club are open for this membership. Please write a Java program (Membership.java) for membership management. The Membership class should have the following public interface: 1. public Membership (String name, int visits): A constructor to set up the member's name and the initial number of visits allowed. The parameter visits is supposed to be positive (if not, initialize the number of visits to 0). 2. public String getName (): An accessor to return the member's name. 3. public int getRemainingVisits (): An accessor to return the number of remaining visits. 4. public boolean isValid (): A method to decide if one's membership is still valid (true if the number of remaining visits is greater than 0; false otherwise). 5. public boolean topUp (int additionalVisits): A method to add additional visits (represented by additionalVisits) to the remainingVisits. Returns true if the top-up succeeds and false otherwise. The top-up succeeds only If the given additionalVisits s non-negative. 6. public boolean charge (): A method that deducts 1 from the number of remaining visits when the membership is valid. Returns true if the charge succeeds and false otherwise. The charge succeeds only if the membership is valid before charging. 7. public boolean equipmentAllowed (): A method that indicates whether the equipment at the gym is available to this kind of membership. Returns true for now; to be updated in Task 2. 8. public boolean classesAllowed (): A method that indicates whether the fitness classes at the gym are available to this kind of membership. Returns true for now; to be updated in Task 2. Write a tester program Task1 Membership Tester to test the class you have written. Follow the examples given in class (e.g., BankAccountTester), and create an object from the class Membership above. Test the public interface of your class thoroughly (each public method must be tested at least once). For accessor methods, print out the expected return value and the return value of your method (see the BankAccount Tester example) to compare. This tester class is not to be submitted for marking, but it is beneficial for you to make sure your Membership class works as intended. 123456 7 8 9 10 11 ---- A class to test the BankAccount class. */ public class BankAccount Tester { 12 13 14 15 16 17 18 } /** Tests the methods of the BankAccount class. @param args not used */ public static void main(String[] args) { } BankAccount harrys Checking harrys Checking.deposit (2000); harrys Checking.withdraw (500); Program Run: = System.out.println (harrysChecking.getBalance () ); System.out.println("Expected: 1500"); 1500 Expected: 1500 new BankAccount ();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Below is the Java program for the Membership class and a tester program MembershipTester public clas... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Accounting and Reporting a Global Perspective

Authors: Michel Lebas, Herve Stolowy, Yuan Ding

4th edition

978-1408066621, 1408066629, 1408076861, 978-1408076866

More Books

Students also viewed these Programming questions