aspose file tools*
The moose likes Beginning Java and the fly likes Describing Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Describing Objects" Watch "Describing Objects" New topic
Author

Describing Objects

Danny Morgan
Greenhorn

Joined: Jul 05, 2008
Posts: 8
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 ]

Regards<br /> <br />Danny
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Danny Morgan
Greenhorn

Joined: Jul 05, 2008
Posts: 8
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Describing Objects