Jump to content

Set the number of values in an arraylist to a variable

- - - - -

  • Please log in to reply
5 replies to this topic

#1
noel222

noel222

    Newbie

  • Members
  • PipPip
  • 25 posts
nevermind I figured it out

Edited by noel222, 23 February 2012 - 03:25 PM.


#2
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts

Quote

I want to set the number of values in an arraylist to a variable
Use a counter starting at zero and add one to it every time you add a value to the arraylist.

The ArrayList class has a method that will tell you the size/number of values in the ArrayList.

#3
noel222

noel222

    Newbie

  • Members
  • PipPip
  • 25 posts
nevermind I figured it out

#4
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts

Quote

it says the bag is full,
Where is the message: "bag is full"? I can not find it.

Add some println statements to the code to show the value of bagSpace every time it changes so you will know what the program is doing.

#5
noel222

noel222

    Newbie

  • Members
  • PipPip
  • 25 posts
My mistake. I meant to say that the message is "can hold more" which can be found in my addingCandyTest() method. I am really just having a lot of trouble with the CantHoldAnyMore() Method. How would I set the bagspace to reflect the amount of candy added to the bad in the addingCandyTest()?

#6
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
Did you look at using the ArrayList method that gives the number of objects it contains?

Quote

How would I set the bagspace to reflect the amount of candy added
Start it at 0 and add one to it every time something was added.

Are you sure that is the correct usage of the bagSpace variable?
Why would its value be passed in the constructor?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users