Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: store a list/string for each object

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question store a list/string for each object

    Hi everyone,

    What im trying to do is add a list of scores to a object called member, only adding one score to the obect at a time, then i need to get the list, sum the values of the list, - 72*the length of the list, im having trouble with adding a list to the member object and hoping someone can help

    String strscore = AppTools.getUserInput(AppConstants.Get_course_score);
    //strmemscoreno = Integer.toString(memArrScore.size() + 1);
     
    //int[] strscore = new int[(AppConstants.MAX_SCORES_FIVE)];
    //int s = 1 + strscore.size();
    //String strMemberId = AppTools.getUserInput(AppConstants.GET_MEMBER_ID);
    int score = Integer.parseInt(strscore);
    int handicap = score - (AppConstants.Get_Handicap);
    if (handicap < 0){ 
    handicap  = 0;
    }
     
    System.out.println("Your handicap is " + handicap);
    counter++;
     
    public int getlistScore() {
         return IntScore;
    }
    public void setlistScore(int IntScore) {
         this.IntScore = IntScore;
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: store a list/string for each object

    trouble with adding a list
    What kind of data is in this list? How to you want to access it?
    Do you know about Collection classes or are you supposed to use an array?

    Your code so far looks a bit of a mess. Where is your main class?
    Where is the member object defined? You'll need to define that so you can add the code for the list.
    Where do you get the numbers in the list? User input or from a file?

    You need to do some more thinking on your design before going on.

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: store a list/string for each object

    what is a collection class, i have not covered that so far in my course, the code so far is about 700 lines and in 7 different classes, so I have just taken some snippets, the numbers are to be from user input, filtering through the list of existing members and requesting input from the user. all the code?

  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: store a list/string for each object

    It would help if you can explain more clearly what you are trying to achieve - do you want to add a number of individual scores to an object that will hold them in a list, or do you want to add a list of scores to the object in one go?

    If the former, create a class with an addScore method that takes the score as a parameter (int?) and adds it to a list member variable in the object. This could be an array or an ArrayList type. If you use an array, you'll need to declare it big enough to hold the maximum number of scores required, and have a count variable to keep track of the number of scores added - so you know where to insert the next one. You'll also need a variable to hold the size, so you can reject score additions when the array is full. If you use an ArrayList you don't need to track the number of items or the maximum size.

    If the latter, create a class with an addScores method that takes an array or ArrayList parameter and assigns it to an array or ArrayList member variable.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: store a list/string for each object

    The Collections I refered to is a generic term for a group of classes that can be used to contain objects.There is an interface: Collections that is part of Sun's Collections Framework. That's probably past what your doing now. You need to look in the Java API to see the classes' definitions.

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: store a list/string for each object

    thanks dlorde, your comments helped out perfectly, all sorted, i was declaring my member as a object at the start of the class and therfore not letting it referance the object(member)

Similar Threads

  1. can store image&text in rms seperately but NOT together :(
    By wildheart25c in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: March 26th, 2010, 07:59 AM
  2. Convert object to String
    By innspiron in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 15th, 2010, 08:48 AM
  3. Create a CLOB object with the string value
    By oshoarun in forum JDBC & Databases
    Replies: 0
    Last Post: March 6th, 2010, 02:54 AM
  4. Replies: 2
    Last Post: February 25th, 2010, 04:17 PM
  5. String substring, concatenation operation on linked list
    By oaks12 in forum Collections and Generics
    Replies: 1
    Last Post: January 15th, 2009, 07:12 AM