Question: A. Write a java program that do the following: Create a class named GymMembership that consists of the following: Three instance data members of private

A. Write a java program that do the following:

Create a class named GymMembership that consists of the following:

  • Three instance data members of private access modifier: memberld: represents the id of the member and its data type is integer. membershipType: represents the display type of the membership and its data type is string. totalfee: represents the cost that members pay and its data type is double.
  • One static data member of public access modifier: membersCounter: keeps track of the number of member's objects that are created from the GymMembership class. Its type is integer.
  • Member methods as follows:
  1. Default constructor to initialize the memberld to zero, membershipType to empty string, and the totalFee to zero.
  2. Parameterized constructor that receives values for the following data members (totalFee, membershipType, and totalfee), then it sets the received values in the class data members.
  3. Create a method named setTotalfee that sets a value in the totalfee data member. Be sure that the value is nonnegative.
  4. Create a method named get Memberld that returns the value of the memberld.
  5. Create a method named isExpensive that returns true if the total fee is more than or equals to

300 JD, and returns false otherwise.

6. Create a method named calculateFee that returns the annual cost required for the membership according to the following:

* If you only enroll for a month (Monthly), the fee to pay is 45 JD. If you want a single yearly payment (Annually), the fees to pay is 35 JD per month. [Hint: = Totalfee =cost per month*number of months]

7. Create a method named showMembershipDetails that prints the values of the data members in the following format:

[Hint: you may use the isExpensive function to detect if the gym membership is cheap or expensivel.

B. Write a Demo class that contains the main method. In the main method do the following:

1. Create an object of the GymMembership class named GymMember1 using the default constructor.

Create another object of the GymMembership class named GymMember2 using the parameterized constructor. Ask the user to input the memberld, membershipType, totalFee.

  1. Call the method setTotalfee for the GymMember1 object to set the price of that object to be 75.
  2. Print the value of the membersCounter static data member.
  3. Call the showMembershipDetails method using the object GymMember1.
  4. Call the showMembershipDetails method using the object GymMember2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!