Results 1 to 9 of 9
  1. #1
    NoobOfJava is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default Question on add method

    .........................................
    Last edited by NoobOfJava; 06-03-2011 at 09:03 PM.

  2. #2
    NoobOfJava is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default

    Can someone help me out on my add method. It has to add an element to the list (goals, assists, ppg, etc). I got the sort, remove, and count to work but no this. This is my project which is due today.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,454
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by NoobOfJava View Post
    Can someone help me out on my add method. It has to add an element to the list (goals, assists, ppg, etc). I got the sort, remove, and count to work but no this. This is my project which is due today.
    You have to ask the user for the relevant data, construct a Pair object out of it and add the new Pair object to your list.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by NoobOfJava View Post
    Can someone help me out on my add method. It has to add an element to the list (goals, assists, ppg, etc). I got the sort, remove, and count to work but no this. This is my project which is due today.
    You've probably left it too late, but if you post up the code for the add method that you have so far, we'll help you fix it.

  5. #5
    NoobOfJava is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default

    I am using the removeOrAdd method, and in that method, the remove part works but not the add part. I tried doing new DataBase().processing(); but that does not add new elements to the previous elements.
    Like for example.
    List
    Andrew

    After adding,
    (Andrew is not there anymore), but a new element(or s) is there.
    Dan
    Chris

  6. #6
    NoobOfJava is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default

    Can you guys please help me out? This assignment is due in 2 hours. Sorry for rushing you guys. I worked hard on this code, and got everything to work except the adding elements part.

  7. #7
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Well, obviously the add part doesn't work. It's an empty block:

    Java Code:
    			if(newVal.equalsIgnoreCase("A"))
    			{  
    				
    			}
    What have you tried to put in there?
    Get in the habit of using standard Java naming conventions!

  8. #8
    NoobOfJava is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default

    I left it blank because I don't understand what to put in there. I tried to put new DataBase().processing(); to call the whole processing method again, but it creates a new list instead of adding it to the previous list.

  9. #9
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Okay. Well, you need to create a new Pair object to put in the list. To do that, you'll need to get all the variables that make up a Pair object.

    Looking at your definition of the Pair class, I really have no idea why you're passing an Object and a Comparable to its constructor. But the other arguments sound like things you should be getting from the user. So use the same techniques you've been using to ask the user for goals, assists, and gamesPlayed. Then use those values to create a new Pair object, and call List.add() to add it to the list.

    List (Java Platform SE 6))
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. WAIT method question
    By alexalex1234 in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-14-2011, 11:37 AM
  2. add method from Arraylist - question
    By Adomini in forum New To Java
    Replies: 6
    Last Post: 10-21-2010, 07:08 PM
  3. return question for method
    By Adomini in forum New To Java
    Replies: 12
    Last Post: 09-02-2010, 04:55 PM
  4. split method question
    By Chasingxsuns in forum New To Java
    Replies: 3
    Last Post: 11-19-2009, 07:19 PM
  5. method question
    By xplayerr in forum New To Java
    Replies: 7
    Last Post: 11-11-2009, 04:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •