• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Describing Objects

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic