• 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

coding Excercise

 
Ranch Hand
Posts: 67
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
Please guide me in doing this excercise

Exercise #1: Develop an inheritance hierarchy, utilizing interfaces, abstract classes, and concrete classes, for two cars and a motorcycle. Decide where the following instance variables should be defined in the hierarchy. Use a default constructor for each Class to assign values to these instance variables. Hint: You should pay special attention to the modifiers (public, private, protected) of the variables.
make � String
color � String
numberOfWheels � int
gearsOnLeft � boolean
numberOfDoors � int
currentSpeed � int
engineState � String
gearPosition - String

Exercise #2: Add methods to change the state of your vehicle. Decide where the following methods should be in your hierarchy. Create logic to not allow the driver to exceed the vehicle�s maximum speed. Hint: The �getMaximumSpeed� method should be a protected abstract method.
startEngine()
increaseSpeed(int amount)
stopEngine()
getMaximumSpeed()
shift(String gearPosition)

Exercise #3: Create a class called �Driver� that contains the three vehicles described above. Use a List to represent the vehicles. Create a �drive� method to iterate over the list of vehicles and drive them in succession. The �drive� method should start the vehicle, shift the gear from park to drive, increase the speed from 0 to 60, and slow down to 0, shift from drive to park, and stop the engine. Create a �main� method to be used to initiate the operation.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bhargavi kurra:
... Please guide me in doing this excercise...


We are happy to guide you, but we will not do it for you.

What have you done so far? Where are you stuck? What are your specific questions?
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch

particularly:
http://faq.javaranch.com/java/DoYourOwnHomework

and:
http://faq.javaranch.com/java/ShowSomeEffort
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[quote=Jayasri Alaparthi]Hi Friends,
                Please guide me in doing this excercise

Exercise #1: Develop an inheritance hierarchy, utilizing interfaces, abstract classes, and concrete classes, for two cars and a motorcycle. Decide where the following instance variables should be defined in the hierarchy. Use a default constructor for each Class to assign values to these instance variables.  Hint:  You should pay special attention to the modifiers (public, private, protected) of the variables.
make � String
color � String
numberOfWheels � int
gearsOnLeft � boolean
numberOfDoors � int
currentSpeed � int
engineState � String
gearPosition - String

Exercise #2: Add methods to change the state of your vehicle.  Decide where the following methods should be in your hierarchy.  Create logic to not allow the driver to exceed the vehicle�s maximum speed. Hint: The �getMaximumSpeed� method should be a protected abstract method.  
startEngine()
increaseSpeed(int amount)
stopEngine()
getMaximumSpeed()
shift(String gearPosition)

Exercise #3: Create a class called �Driver� that contains the three vehicles described above.  Use a List to represent the vehicles.  Create a �drive� method to iterate over the list of vehicles and drive them in succession.  The �drive� method should start the vehicle, shift the gear from park to drive, increase the speed from 0 to 60, and slow down to 0, shift from drive to park, and stop the engine. Create a �main� method to be used to initiate the operation.[/quote]
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the the Ranch
Why have you simply copied the original post? Are you doing the same exercise? We don't simply supply solutions to questions, but if you would like to show us what you have done so far and what problems you are facing, we shall be happy to help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic