Gym Membership

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 2083 Views - Last Post: 15 March 2018 - 07:38 PM Rate Topic: -----

#1 redstar81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 02-March 18

Gym Membership

Posted 02 March 2018 - 06:47 AM

Could any assist I am learning java as part of my University Course, could anyone assist me please. If I need to build a gym membership which devises a fee for it members

public class Gym{

String membership name;
int cost;
int membership length;


Not sure if this is a correct start to code this right. Again any pointers, would be appreciated

This post has been edited by Martyr2: 02 March 2018 - 05:44 PM
Reason for edit:: Added code tags. [code]your code goes in between[/code]

Is This A Good Question/Topic? 0
  • +

Replies To: Gym Membership

#2 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 699
  • View blog
  • Posts: 5,361
  • Joined: 25-December 13

Re: Gym Membership

Posted 02 March 2018 - 06:52 AM

Please use the [CODE] button to wrap code tags around your code.

Quote

Not sure if this is a correct start to code this right.

It's not. There needs to be an ending } for the class. Remove the []s
After you add the ending } compile the code to let the compiler check it for valid syntax.

If you have questions about any error messages, copy the full text and paste it here.

This post has been edited by NormR: 02 March 2018 - 06:54 AM

Was This Post Helpful? 1
  • +
  • -

#3 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5259
  • View blog
  • Posts: 14,073
  • Joined: 18-April 07

Re: Gym Membership

Posted 02 March 2018 - 05:51 PM

I am not sure how far you are suppose to take the concept of a membership but if you are building a bigger system then you might want to make the actual membership a class.

public class Membership {
    private String membershipName;
    private double membershipFee;

    public Membership(String name, double fee) {
        membershipName = name;
        membershipFee = fee;
    }
}



Then of course you would create a class for a Gym member who has a membership. That Gym member might be part of a collection of Gym members known as a Gym.

public class Gym {
    private GymMember[] members;

    public Gym() {

    }

    public void AddMember(GymMember member) {

    }
}



Hope you get the idea. I will leave it to you to create the GymMember class and fill in the necessary lines of the Gym class I have done above. If you need JUST the membership, then I think what I have provided above for Membership will be 95% of what you probably want.

:)
Was This Post Helpful? 2
  • +
  • -

#4 redstar81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 02-March 18

Re: Gym Membership

Posted 04 March 2018 - 04:28 PM

{

  public static void main ( String[] args )

  {

    //  define constants


    final double REGISTRATION_FEE       = 10;        // fee all new members pay

    //  Input Variables

    char major;                                  // 'G' General Member or 'S'Student

                                                 // '18' under 18's

    //  General Calculation Variables

    double hours_amount, state_fee, major_code;

 

    //  Output Variable

    double total_cost;                              // calculated cost

    //  Set up for Formatted output

    NumberFormat curr_f = NumberFormat.getCurrencyInstance();

    String str_cost;

 

    //  Set up for user input

    Scanner input = new Scanner( System.in );


    // Read Inputs

    System.out.println ( "Please enter membership ('G' for General Member, 'S' for student or '18' under 18's): " );


    major = input.nextLine().charAt(0);

    {

    // Costs of membership

    if (membership == 'G' || membership == 'G' )

    {

        membership_code = GENERAL_MEMBERSHIP;                      // Assign

    }

    else if (membership == 'S' || membership == 'S')

        {

        membership_code = STUDENT_MEMBERSHIP;                      // Assign

        }

            {

            else

            membership_code = Under_18;

            }

    }

 

    // Calculate fee



Ok so I need to work out the fees for membership, members are charged a rate depending upon the Grade-so General member would be charged £50.

Now I am not sure what I have wrote is going in the right direction and if this would be right way to calculate charges etc

This post has been edited by ndc85430: 04 March 2018 - 10:51 PM
Reason for edit:: Fixed code tags.

Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 699
  • View blog
  • Posts: 5,361
  • Joined: 25-December 13

Re: Gym Membership

Posted 04 March 2018 - 04:33 PM

Please wrap code in code tags: Posted Image

Quote

way to calculate charges

Can you describe how you would calculate the charges manually with paper and pencil?
Was This Post Helpful? 1
  • +
  • -

#6 redstar81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 02-March 18

Re: Gym Membership

Posted 05 March 2018 - 12:33 AM

So to quote them manually I would look at the Grade so for a General Member it would be £50, if they have just joined it would be a joining fee, however I would also need to charge them £10 per year

Joining Fee £25
General member fee £50
Yearly fee £10

25+50+10

This post has been edited by andrewsw: 05 March 2018 - 02:42 AM
Reason for edit:: removed previous quote, just use the REPLY button

Was This Post Helpful? 0
  • +
  • -

#7 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 699
  • View blog
  • Posts: 5,361
  • Joined: 25-December 13

Re: Gym Membership

Posted 05 March 2018 - 06:42 AM

Before going any further with the code, compile the current code and fix all the compiler errors. When there are no compiler errors, post the new code and ask your questions about what you want to do next.



Quote

the Grade so for a
General Member it would be £50,
if they have just joined it would be a joining fee,
however I would also need to charge them £10 per year

That looks like a place for if statements to detect each of those conditions and add in the appropriate amounts. Do you have questions about the code for that?

This post has been edited by NormR: 05 March 2018 - 06:44 AM

Was This Post Helpful? 0
  • +
  • -

#8 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2587
  • View blog
  • Posts: 10,368
  • Joined: 03-December 12

Re: Gym Membership

Posted 05 March 2018 - 06:59 AM

I'll go one step further. Stop coding. Write out a flow diagram before you write another line of code. Then, you will know what you need to write.
Was This Post Helpful? 1
  • +
  • -

#9 redstar81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 02-March 18

Re: Gym Membership

Posted 11 March 2018 - 04:24 PM

Hi

I have hopefully progressed further now, If someone could assist me on how the if statements would show the various types of memberships that I have



// cost1 = 100;      General fee
// cost2 = 55;       Student fee
// cost3 = 35;       Under 18 fee
// cost4 = 10;       Competition fee - this is charged every year for members


// f1 = 25;      // Joining fee for General Membership
// f2 = 15;      // Joining fee for Student Membership
// f3 = 8;       // Joining fee for Under 18 Membership
        
  

//  Set up for user input
  Scanner input = new Scanner( System.in );	
  
/********************************************************************/
System.out.println ("Is this a new member?");

type = input.nextLine().charAt(0);  
System.out.println ("Sign them up for membership");


System.out.println("Select membership type ('G' for General Membership, 'S' for Student, or 'U' for Under eighteen");

type = input.nextLine().charAt(0);  

System.out.println ("Please enter membership cost");

cost1 = input.nextInt();

System.out.println ("Please enter joining fee");

f1 = input.nextInt();

System.out.println ("Please enter competition fee");

competition = input.nextInt();

total = cost1 + f1 + competition;

System.out.println ("Total: " + total);






} end class

Was This Post Helpful? 0
  • +
  • -

#10 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2587
  • View blog
  • Posts: 10,368
  • Joined: 03-December 12

Re: Gym Membership

Posted 11 March 2018 - 04:32 PM

How far into class are you?


The reason I’m asking is, I want to know if you understand how classes and polymorphism works. For instance, you ask the user to input various fee’s, but wouldn’t that be derived based on the membership type?
Was This Post Helpful? 0
  • +
  • -

#11 redstar81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 02-March 18

Re: Gym Membership

Posted 11 March 2018 - 04:45 PM

So would I need to create another class and then reference it with this class?
Was This Post Helpful? 0
  • +
  • -

#12 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2587
  • View blog
  • Posts: 10,368
  • Joined: 03-December 12

Re: Gym Membership

Posted 11 March 2018 - 05:07 PM

I see at least a couple classes. You have members, and memberships. Those memberships have types. So if you had a General membership type, whether derived from a parent membership type, or its own class, would tell you the fees associated, right?
Was This Post Helpful? 0
  • +
  • -

#13 redstar81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 02-March 18

Re: Gym Membership

Posted 11 March 2018 - 05:16 PM

So would it be for example

Public Class Membership {

The reference the membership type and fees associated?

This post has been edited by ndc85430: 13 March 2018 - 07:39 AM
Reason for edit:: Removed quote of previous post.

Was This Post Helpful? 0
  • +
  • -

#14 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2587
  • View blog
  • Posts: 10,368
  • Joined: 03-December 12

Re: Gym Membership

Posted 11 March 2018 - 05:20 PM

Basically. So you have a Membership class; and an enumerated MembershipType. Based on the type passed in when you instantiate the Membership class, it will populate the fee's associated by that type.

Have you gotten to that point yet, or is there anything I said that you don't understand?
Was This Post Helpful? 0
  • +
  • -

#15 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2587
  • View blog
  • Posts: 10,368
  • Joined: 03-December 12

Re: Gym Membership

Posted 11 March 2018 - 06:08 PM

Here is sort of an example to show what I mean, with some details missing for you to struggle through to answer them.
ArrayList<Member> members = new ArrayList<>();
members.add(new Member("John", "Doe", MembershipType.Student));
members.add(new Member("Harry", "Lee", MembershipType.General));
members.add(new Member("Sofia", "Long", MembershipType.UnderEighteen));




And that would output something like this,

Quote

Membership Number			Type		Start		Name		Join	Member
4de7fb67-0149-4047-a6ed-39772f9c4296	Student		2018-03-11	Doe, John	$10	$55
00e2a107-bd9d-4dc5-ae79-1874cdc1d9ef	General		2018-03-11	Lee, Harry	$25	$100
8b679f32-5b1a-45f6-86e5-926ff158c79b	UnderEighteen	2018-03-11	Long, Sofia	$8	$35

This post has been edited by astonecipher: 11 March 2018 - 08:40 PM
Reason for edit:: Better version

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3