Problem Statement:
Suppose we have a class named as Train it has two constructors, two methods, and a single attribute each of which described as follows:
• One attribute:
maxSpeed – an int value representing the maximum speed of the Train object.
Note: Train speed of modern Trains may be something like 250 km per hour, so a value you could use for testing purposes is 250.
• Two constructors:
A default constructor:
A constructor that initializes the attribute ms where ms is the maxSpeed.
An overloaded constructor:
A constructor that takes ms as an argument, where ms is the maxSpeed.
• Two methods:
getMaxSpeed() – return the maxSpeed value associated with the Train object.
setMaxSpeed(ms) – change the maxSpeed value associated with the Train object, where ms is the new value.
• Display the value through default constructor and overloaded constructor.
• Display setter value through main function.
Sunday, January 24, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment