Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Describing Objects

 
Danny Morgan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me to understand this more fully. I don't understand what is happening with; (smash.setNewSeconds(30) == true) & (smash.setNewSeconds(90) == true), and what does the value inside the bracket mean?




When I run the program the output is:


There are 3 viruses.

The smash NewVirus object has a newSeconds value of 0

Attempting to change the value of newSeconds to 20.

Attempt failed.

The smash NewVirus object has a newSeconds value of 0

Attempting to change the value of newSeconds to 90.

Attempt succeeded.

The smash NewVirus object has a newSeconds value of 90


[ July 05, 2008: Message edited by: Danny Morgan ]
[Also by Campbell Ritchie to add code tags]
[ July 05, 2008: Message edited by: Campbell Ritchie ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

"smash" references an instance of NewVirus, and NewVirus has a method called setNewSeconds...

Basically, this method checks to see if the int parameter (the value in the parentheses) is greater than 59 and less than 101. If it is, then the method sets "newSeconds" to this value and returns true. Otherwise, it returns false.

So the expression...

(smash.setNewSeconds(30) == true)

...passes the value 30 to this method, then uses the comparison operator == to test whether smash.setNewSeconds(30) is true -- that is, whether "newSeconds" was set to 30 or not.
 
Danny Morgan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply marc weber it was a great help! I understand the code fully now!

[ July 05, 2008: Message edited by: Danny Morgan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic