Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Vehicle

dickersonka
dickersonka 


Create a class named Vehicle that acts as a super class for vehicle types. The Vehicle class contains private variables for the number of wheels and the average number of miles per gallon. The Vehicle class also has a constructor with integer arguments for the number of wheels and average miles per gallon and a toString() method that returns a String containing these values. Create two subclasses, Car and MotorCycle, that extend the Vehicle class. Each subclass contains a constructor that accepts the mile-per-gallon value as an argument and forces the number of wheels to the appropriate value—2 for MotorCycle and 4 for Car. Write a UseVehicle class to instantiate one Vehicle object, one Car object, one MotorCycle object, and display each object’s values. Attachments
Tags Clarifications

Answers

Java - Vehicle - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Vehicle assignment including source and comments Attachments
Vehicle.zip (1 K) Download
Preview
public MotorCycle(int averageMPG) { super(2, averageMPG); }

Preview
9 //Description of program: Represents a Car with 4 wheels public class

Preview
MotorCycle motorCycle = new MotorCycle(45); Car car = new Car(28); System.out.println("MotorCycle = " +

Preview
private int numberOfWheels; private int averageMPG; public Vehicle(int numberOfWheels, int averageMPG) { this.numberOfWheels = numberOfWheels; this.averageMPG = averageMPG;

Screenshots
Purchase Answer

Solution

zkingleo2009
zkingleo2009 



Attached is the solution to above problem. Attachments
vehicle.zip (1 K) Download
Preview
extends Vehicle { public Car(int

Preview
public motorCycle(int milesPerGallon) { super(2,

Preview
class UseVehicle { public static void main(String[] args) {

Preview
toString() { return ("Num of Wheels: " + wheels + "\nMiles per Gallon: " + mpg);

Screenshots
Purchase Answer

Vehicle Solution

uetian_cute
uetian_cute 



All the files and a screenshot of output are included. Attachments
Vehicle.zip (15 K) Download
Preview

Preview
private int numberOfWheels; private int averageMPG; public Vehicle(int wheels, int mpg) { numberOfWheels = wheels; averageMPG = mpg;

Preview
public void setNumberOfWheels(int numberOfWheels) { super.setNumberOfWheels(numberOfWheels); } public

Preview
} public void setNumberOfWheels(int numberOfWheels) { super.setNumberOfWheels(numberOfWheels);

Preview
public static void main(String[] args) { Vehicle vehicle

Screenshots
Screenshot
Purchase Answer

Java Program to represent Vehicle,Car and Bike Object

ravi_singh
ravi_singh 



I have provided Solution as well as screen shots please Ask if you have any Doubt. Attachments
Bike.java (1 K) Download Preview
mPG=m; } public String toString(){ return "Bike\nNumber

Car.java (1 K) Download Preview
m){ numWheels=4; mPG=m; } public String

Vehicle.java (1 K) Download Preview
mPG; public Vehicle(int nw,int m){ numWheels=nw; mPG=m;

Test.java (1 K) Download Preview
public static void main(String[] args){ Vehicle v=new Vehicle(4,10);

Sol.png (4 K) Download Preview

Screenshots
Screenshot
Purchase Answer

Java Program to represent Vehicle,Car and MotorCycle Object and UseVehicle class to test it

ravi_singh
ravi_singh 



Provided Java Classes code along with screenshots.
please ask if you have any doubt.
Attachments
Sol.png (4 K) Download Preview

Car.java (1 K) Download Preview
mPG=m; } public String toString(){ return

MotorCycle.java (1 K) Download Preview
public String toString(){ return "MotorCycle\nNumber Of Wheels:"+numWheels+"\nMiles Per

Vehicle.java (1 K) Download Preview
} public String toString(){ return "Vehicle\nNumber Of Wheels:"+numWheels+"\nMiles

Screenshots
Screenshot
Purchase Answer