This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Murach's Java Programming and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Add Method with two parameter  RSS feed

 
Constantin Cornea
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, Everyone !! Maybe some of you already recognise me from the "Array topic" with increasing the size:-D ... yeah was a little bit
challenging

but now I have an easier question but I just can't figure out how to implement the Add Method in the ArrayList when I have two parameters?

so, as usual, I upload here a photo of my UML class where I have the method which I am struggling with and also the piece of code how I tried to do






Order.JPG
[Thumbnail for Order.JPG]
 
Norm Radder
Rancher
Posts: 2037
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to implement the Add Method in the ArrayList when I have two parameters?

Can you define what the two parameters would be and how their values would be used by the add() method?

Note: Java coding conventions recommends that variable names start with lowercase letters: orderLines
 
Carey Brown
Bartender
Posts: 2697
41
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constantin Cornea wrote:

Where you declare orderLines it is an ArrayList containing objects of type OrderLine. Where you call add() you can only add an OrderLine object so you'll need a way to convert amount and item into an OrderLine and then add that.
 
Carey Brown
Bartender
Posts: 2697
41
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your UML diagram has the definition of Order( int maxNumberOfLines ), this seems like a way to allocate an array of that number of OrderLines. I would agree with you that an ArrayList would have been preferred over an array but your UML tells me that they want an array.

Edit:
On second thought, max might just be something you have to compare the size() of the ArrayList to, to prevent you from adding any more OrderLines.
 
Constantin Cornea
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this the final two classes which I have to implement

the OrderLine I implemented and now I am implementing the Order class and this is an ArrayList class

I don't have a field such size or a method like doubleCapacity and stuff like that

this is ArrayList
Order_UML.JPG
[Thumbnail for Order_UML.JPG]
 
Campbell Ritchie
Marshal
Posts: 54882
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for being late to the party, but:

CC: please indent the code correctly. You can perpetrate nasty errors in the code and not see them because of the poor indentation.
Where does it say anything about maximum number of lines? I thought the int field was a count of how many lines you have. And where does it say you have to use an array or a List or any particular data structure. The UML pictures shown here don't mention it. Or was it on CC's other thread? Ah, here it is. I found out whilst reviewing a book recently that you can use the Arrays#copyOfRange method to create a larger array; you have to set one of the arguments bigger than you would have expected.

I don't like assignments where so much information is provided; they are not testing programming skills so much as code monkey skills.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!