• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anyone help explain this interface/innerclass example?  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I missed class few days ago due to a family emergency, I missed the lecture on this example. I had a classmate send the file.





I pretty much get the program but in the InventoryItem class on line 40, what is it exactly translating? Same with line line 19 on the driver class, what does that for loop translate in terms of dumbing it down for me in for(int i; i<something;i++). And what is 14 doing? I don't think i seen tthis before. Hope you can help I'd email my professor but she nvr replies soon until like last minute! She lags it... lol
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good tutorial on conditional operators here for your question about line 40 : http://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html

As to line 19 of your InventoryItemDriver class, notice what happens when it creates a new InventoryItem... Do you see what it passes in the constructor (one of the values is the Id)? See the use of "this" in the constructor. The compareTo method is an implementation of part of the contract with Comparable (which you can read about in the API).
 
Raven Ramirez
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so on line 40, it's just an if/else? So if one ID number is bigger it deceases by one, else it increments? Not exactly sure what it translates still. And sry I actually meant line 17 on the driver class not 19.
 
Alvin Parker
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 40 is a returning a value. It is not incrementing or decrementing. It is essentially saying :

If uniqueId is less than uniqueItemId, return something, (else) evaluate another if statement - read it closely with a good understanding of the ternary operator.

Line 17 is a 'for each'. Do a search for "Java For Each" and you'll understand how that statement works.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!