Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    2
    ReputationRep:
    Could anyone help me with this question not sure what to do

    [10 marks] Define a new method in the Member class to register the member on a given fitness activity. It takes an object of the Activity class and returns nothing. It is assumed that each activity is restricted to maximum 20 people. This method should check first if there is a place on the given activity. If so it registers the member on the given activity; otherwise it prints an appropriate message instead.
    Online

    9
    ReputationRep:
    Do you already have code for the Member class? Because what attributes the Activity class has and whether they are public or not will mean the question should be approached differently
    • Thread Starter
    Offline

    2
    ReputationRep:
    Yeah i do, When a member is created the parameters are Id, name and gender. In the lecture the teacher said that we aren't supposed to edit the activity and also instructor class to do this but I dont know how to access the variables from the activity class without changing it.
    Online

    9
    ReputationRep:
    What attributes and methods does Activity have?
    • Thread Starter
    Offline

    2
    ReputationRep:
    private String title;String day; Instructor instructor; int totalMembers;

    public String getTitle(), public String getDayOfWeek(), public Instructor getInstructor(), public void setInstructor(Instructor instructor), public int getTotalMembers(), public void setTotalMembers(int number), public void print()
    Online

    9
    ReputationRep:
    So the register method will need to be a void type, and have a parameter of the Activity object so:

    Code:
    void register(Activity activity)
    {
        //your code here
    }
    You will then need to check to see if the activity is full, you can do this using an if statement along the lines of

    Code:
    if(activity.getTotalMembers() < 20) { 
     activity.setTotalMembers(activity.getTotalMembers() + 1)
    }
    and then run an else statement that prints out a message saying that the activity is full



    As there seems to be no list of members in the Activity function that you've mentioned I don't know whether you are required to add the member to a list elsewhere.

    I hope this has been a help!
    • Thread Starter
    Offline

    2
    ReputationRep:
    Yes it did work thanks !!!!!!!!!!!!!
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Will you be richer or poorer than your parents?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.