Gym Membership

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

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

#16 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 12 March 2018 - 12:12 AM

That perfect, understand where I was going wrong. I will the classes and then run my code. Thank you, I will let you know I get on

*Sorry I will build the classes *
Was This Post Helpful? 0
  • +
  • -

#17 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 12 March 2018 - 01:53 AM

View Postastonecipher, on 11 March 2018 - 06:08 PM, said:

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





public class Membership {
	private String membershipName;
	private double membershipFee;
	
	public Membership (String name, double fee) {
		membership.Name = name;
		membership.Fee  = fee;
		
	}
	
	{
		ArrayList<Member> members = new ArrayList<>();
		members.add(new Member ("John"  , "Smith",   MembershipType.Student));
		members.add(new Member ("Andrew", "Johnson", MembershipType.General));
        members.add(new Member ("Sarah", "Nimmo",    MembershipType.UnderEighteen));

	}
	


Am I on the right track or am I missing something?
Was This Post Helpful? 0
  • +
  • -

#18 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3567
  • View blog
  • Posts: 16,264
  • Joined: 20-September 08

Re: Gym Membership

Posted 12 March 2018 - 02:51 AM

Quote

Am I on the right track or am I missing something?

What you're attempting to do looks OK but does it compile?
Was This Post Helpful? 0
  • +
  • -

#19 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 12 March 2018 - 07:15 AM

Just to check would this go into a class called Membership?


public class Membership{

ArrayList<String> obj = new ArrayListString<String>();

obj.add("General Membership");
obj.add("Student Membership");
obj.add("Under eighteen Membership");
        

public void AddMember (GymMember member){

	    ArrayList<Member> members = new ArrayList<>();
		members.add(new Member ("John"  , "Smith",   MembershipType.Student));
		members.add(new Member ("Andrew", "Johnson", MembershipType.General));
                members.add(new Member ("Sarah", "Jones",    MembershipType.UnderEighteen));
		
		}

Was This Post Helpful? 0
  • +
  • -

#20 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

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

Re: Gym Membership

Posted 12 March 2018 - 07:41 AM

The arraylist itself, shouldn't. That is where you are building the people to add. That would be in your driver.
Now, AddMember *could*, but that is also what the constructor does.


What is all of your current code? So, I can see how you are linking things together.
Was This Post Helpful? 0
  • +
  • -

#21 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 13 March 2018 - 06:23 AM

Played about with it and rebuilt it


public class GymMember {

    // let give some class variables
    
    // static variable do not get created for every instance of the class
    
    public static int COST_GENERAL_FEE = 100;
    public static int COST_STUDENT_FEE = 55;
    public static int COST_UNDER18_FEE = 35;
    public static int COST_COMPETITION_FEE = 10;
    
    public static int MEMBERSHIP_JOINING_FEE_GENERAL = 25;
    public static int MEMBERSHIP_JOINING_FEE_STUDENT = 15;
    public static int MEMBERSHIP_JOINING_FEE_UNDER18 = 8;
    
    // normal variable defined for each instance
    
    public static String name;
    public static int fee;
    
    // constructor for the class
    
    public GymMember(String name, int fee_cost, int fee_join, boolean compo) {
        this.name = name; // this. means use the classes version and assign to parameter
        fee = fee_cost + fee_join;
        
        if (compo == true) {
            fee += 10;
        } // need to do something here
    }
    
    // Now a function to display the information
    
    public void display() {
        System.out.println("Name: " + name +
                ", fee: " + fee); // you can add more here
    }
    
    // main() is the entry point when the program is run
    
    public static void main(String[] args) {
        // setup a class for some members
        GymMember bryan = new GymMember("Bryan", COST_GENERAL_FEE, MEMBERSHIP_JOINING_FEE_GENERAL, true);
        GymMember jim = new GymMember("Jim", COST_STUDENT_FEE, MEMBERSHIP_JOINING_FEE_STUDENT, true);


		}
		
		bryan.display();
        jim.display();
}


Was This Post Helpful? 0
  • +
  • -

#22 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

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

Re: Gym Membership

Posted 13 March 2018 - 07:17 AM

Not bad. Good use of constants. Here is was my version, I see you started seeing where I was going.

GymMembership
Was This Post Helpful? 0
  • +
  • -

#23 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 13 March 2018 - 07:24 AM

Any ideas for improvement or next steps?

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
  • +
  • -

#24 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

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

Re: Gym Membership

Posted 13 March 2018 - 07:34 AM

Rather than doing display(), you can override the toString method for the class.
You also need to get the main method out of that class. The GymMember class should model the data, and have a driver class, where the main method is, to utilize the class. Otherwise, you are binding the class to an implementation and it is tightly bound to an implementation.
Was This Post Helpful? 0
  • +
  • -

#25 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 13 March 2018 - 07:35 AM

Could you give me an example?

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

Was This Post Helpful? 0
  • +
  • -

#26 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

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

Re: Gym Membership

Posted 13 March 2018 - 07:38 AM

On?
Was This Post Helpful? 0
  • +
  • -

#27 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 869
  • View blog
  • Posts: 3,492
  • Joined: 13-June 14

Re: Gym Membership

Posted 13 March 2018 - 07:41 AM

redstar81, there's no need to keep quoting the previous post. Please just press "Reply" in future. Also, astonecipher's instructions seemed pretty self explanatory. What didn't you understand?
Was This Post Helpful? 1
  • +
  • -

#28 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 13 March 2018 - 07:41 AM

Sorry, please ignore that request

Would I create another class and have it reference this class?
Was This Post Helpful? 0
  • +
  • -

#29 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

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

Re: Gym Membership

Posted 13 March 2018 - 07:43 AM

Have you looked at the repo I linked to?
Was This Post Helpful? 1
  • +
  • -

#30 redstar81   User is offline

  • New D.I.C Head

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

Re: Gym Membership

Posted 13 March 2018 - 07:45 AM

Yes I did. Just looking through it now.

Starting to get a real good understanding of java, thank you for help
Was This Post Helpful? 0
  • +
  • -

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