• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random generation

 
Alexandra Johnson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ill give it a go
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic