• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use setter to "connect" an object and have it recognized as being connected  RSS feed

 
Ted Schrey
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a real long shot, but I'm getting desparate. Not sure if this works, but my code is at this link:

https://tmc.mooc.fi/mooc/paste/3QUlm1QMZCUFmbaXxWTw2w

The part of this assignment that I am stuck on is in MilkingRobot class. the setter is supposed to "connect" a BulkTank Object. if the BulkTank is never connected, I am supposed to throw an IllegalStateExeption error in the milk() method in MilkingRobot class. I am using the variable 'tank' left unset (default to null), so if BulkTank is not passed in through the setter it doesn't get "connected", but this of course gives a NullPointException. What am I not understanding about what constitutes an IllegalStateException, or more to the point, how do I set the state of my tank as not being connected if not by null? I have to have the variable there so it can be "connected" with the setter (and retrieved with the getter).
 
Ted Schrey
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cancel request: I changed from try/catch to if/throw (new IllegalStateExcetption()) and got it to work...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!