Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes please help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please help me" Watch "please help me" New topic
Author

please help me

nadeem akhtar
Greenhorn

Joined: Oct 17, 2009
Posts: 12
Problem Statement

Write the code to implement the concept of inheritance for Vehicles. You are required to implement inheritance between classes. You have to write four classes in java i.e. one super class, two sub classes and one driver class.

Vehicle is the super class whereas Bus and Truck are sub classes of Vehicle class. Transport is a driver class which contains main method.


Detailed description:


Detailed description of Vehicle (Super class):

The class Vehicle must have following attributes:

1. Vehicle model
2. Registration number
3. Vehicle speed (km/hour)
4. Fuel capacity (liters)
5. Fuel consumption (kilo meters/liter)

The Vehicle class must have following methods:

1. Parameterized constructor that will initialize all the data members with the given values.
2. Getters and Setters for each data member that will get and set the values of data members of class.
3. A method fuelNeeded() that will take distance (in kilo meter) as an argument. It will calculate the amount of fuel needed for the given distance and will return the value of fuel needed for given distance. You can use the attributes ‘Fuel consumption’ defined within above Vehicle class to determine the fuel needed for the given distance. You are required to implement this functionality by yourself.
4. A method distanceCovered() that will take time (in hours) as an argument. It will calculate the distance for the given time and speed and returns the value of distance. The formula to calculate speed is given as speed = distance/time. You can use this formula to calculate the distance.
5. A display() method that will display all the information of a vehicle.


Detailed description of Truck (Sub class):

The class Truck must have following attribute:
Cargo weight limit (Kilo grams)

The above class must have following methods:

1. Parameterized constructor that will initialize all data members with the given values.
2. Getters and setters for each data member that will get and set the values of data members of class.
3. It must also override the display() method of Vehicle class and must call display() method of super class within overridden method.


Detailed description of Bus (Sub class):

The class Bus must have following attribute:
No of passengers


The above class must have following methods:

1. Parameterized constructor that will initialize all the data members with given values.
2. Getters and setters that will get and set the value of each data member of class.
3. It must also override the display() method of Vehicle class and must call display method of super class within overridden method.

Create a class Transport which contains the main method. Perform the following within main method:

• Create an instance of class Truck and initialize all the data members with proper values.
• Create an instance of class Bus and initialize all the data members with proper values.
• Now, call fuelNeeded(), distanceCovered() and display() methods using objects of these classes.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Maybe you and your classmate could work together on this assignment?


[Jess in Action][AskingGoodQuestions]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

http://faq.javaranch.com/java/UseAMeaningfulSubjectLine


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38025
    
  22
Aren't you going to welcome a newcomer?

nadeem akhtar, welcome to JavaRanch and have a look at the thread Ernest quoted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please help me
 
Similar Threads
Abstract classes vs polymorphism
method Overriding - Class Bus extends Vehicle, Class Car extends Vehicle
Querying collections (interfaces)
Code Help
"is a" and "has a"