wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Random generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random generation" Watch "Random generation" New topic
Author

Random generation

Alexandra Johnson
Greenhorn

Joined: Dec 02, 2003
Posts: 7
hi, i need help with this question
Design and implement a hierarchy for the following weather warnings: Normal, HighWind, Storm, Tornado, Snow, SnowStorm, Blizzard, Frost, Mist. Each class/object should be able to respond to the following method calls: ``report'' and ``action''. Write a driver program that asks the user for the number of weather warnings (s)he wants to create. Use this input to randomly create the necessary objects and store them in a container class. Use polymorphism to print out the reports of each of the warnings and associate actions.the proper use of abstract classes, inheritance and polymorphism is critical
I have done the following hierarchy
Weather (is at the top of hier. also an abstract class)
|
Normal , Snow, Highwind, mist, frost (they all extend from weather)
|
|snowstorm, blizzard(extend from snow)|,|Storm, Tornado(extend from highwind)|
what i wanna know is how to go about writing the driver programme.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Here's some pseudocode which may point you in the right direction:

If you've overriden the toString() method of each of your classes so that it displays the proper weather warning, something like the above will work. Of course there are a million ways to do something like this, for example you could use an array instead of the static ints, but the above is an easy to read and easy to understand way of approaching a problem such as this.
HTH
[ January 06, 2004: Message edited by: Jason Menard ]
Alexandra Johnson
Greenhorn

Joined: Dec 02, 2003
Posts: 7
thanks ill give it a go
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random generation
 
Similar Threads
coding Excercise
TAAPMAAN
Inheritance with two Children?
Abstract classes vs. interfaces
Polymorphism: to overriding, not to overloading