art1210's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
New Members
Active Posts:
5 (0.01 per day)
Joined:
15-November 12
Profile Views:
203
Last Active:
User is offline Mar 30 2013 12:53 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   art1210 has not set their status

Posts I've Made

  1. In Topic: Storing a list of clubs with students inside

    Posted 20 Mar 2013

    View Postpbl, on 20 March 2013 - 02:36 PM, said:

    Your cClub class is not really correct
    The outside world shouldn't know how it works inside to you can store your Pupils in an array, a lList, a Databse, a flat file...
    all that to say that the creator of the Club class should just pass the name to the constructor

    import java.util.*;
    class Club{
        private String name;
        private List<Pupil> pupils;
        /**
         * Constructor
         * @param name The name of the club
         */
    
        public Club(String name) {
            this.name=name;
            pupils = new ArrayList<Pupil>();  // or LinkedList or... the Collection you want
            
        }
        @Override public String toString(){
            return this.name;
        }
    
        public String getName() {
            return name;
        } 
         */
        public void addPupil(Pupil p){
            pupils.add(p); 
        }
    }
    
    

    Thanks,corrected. Any further help or tips? :)
  2. In Topic: Storing a list of clubs with students inside

    Posted 20 Mar 2013

    View PostTakk, on 19 March 2013 - 08:41 PM, said:

    Given you have multiple classes and lists, you are essentially doing so already...

    if you have a list of clubs(classes)
    and a list inside of the clubs classes which stores a list of pupils..

    it appears this is done already? Or is there more to your question?


    addPupilToClub is already a method of your AfterSchoolBase class, as I understand it, this is what you're trying to accomplish correct?

    Sorry if i'm completely lost in your question, but I'll be happy to lend more assistance if you can point me in the right direction..

    Furthermore, consider the fact that all lists hold objects, and all classes are objects, so if in your main class you have listObjectMain<ObjectClubs>, which holds a collection of ObjectClubs, and inside of each ObjectClubs you have listObjectPupils<ObjectPupils> which holds a collection of ObjectPupils, then you have essentially completed your task so long as you add the Pupils to the listObjectPupils<> inside of the correct instance of ObjectClubs.

    Hope the last bit doesn't throw you off :)/>

    You didn't confuse me, at all. Actually, I understand the whole thing better now so big thank you.

    Yeah, the addPupilToClub method is given with all the parameters and all I have to do is to write up a main body for the method. However, I wasn't sure whether what I've done so far is correct and that the method actually adds a pupil to a specified club. And

    I've got another question. I have to design a method which gets a number of pupils in a club depending on a club. To be honest, I do not know how to get all of the club pupils. How do I search for a club by a name and then get pupils for that club? Will I need another method in Club class to get the club pupils list?

    Here's what I have to design:
    /**
    129	     * Get the number of pupils in a club
    130	     *
    131	     * @param clubName The name of the club.
    132	     * @return The number of pupils in the club.
    133	     */
    134	    public int getNbrPupilsForClub(String clubName) {
    135	        return 0;
    136	    }
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

art1210 hasn't added any friends yet.

Comments

art1210 has no profile comments yet. Why not say hello?