Class Vehicles Java Exercise - Java Programming Course

 Exercise

Class Vehicles

 Objetive

Create a project and the corresponding classes (using several files) for this classes diagram. Each class must include the attributes and methods shown in the diagram, as well as Get and Set methods for Vehicle and "Has" methods ("HasDualSlidingDoors") for MiniVan.

You must create also a test program, which will create an object belonging to each class and tell it to "Drive".

 Example Code

private package_Renamed Vehicles;
public class Car extends_Renamed Vehicle
{

}

package Vehicles;
public class ExcursionVan extends Van
{
}

package Vehicles;
public class Minivan extends Van
{
	protected boolean cargo_Net;
	protected boolean dual_Sliding_Doors;

	public Minivan()
	{
	}
	public Minivan(boolean cargo_Net, boolean dual_Sliding_Doors)
	{
		this.cargo_Net = cargo_Net;
		this.dual_Sliding_Doors = dual_Sliding_Doors;
	}

	public final void SetCargoNet(boolean cargo_Net)
	{
		this.cargo_Net = cargo_Net;
	}
	public final void SetDualSlidingDoors(boolean dual_Sliding_Doors)
	{
		this.dual_Sliding_Doors = dual_Sliding_Doors;
	}

	public final boolean HasCargoNet()
	{
		return cargo_Net;
	}
	public final boolean HasDualSlidingDoors()
	{
		return dual_Sliding_Doors;
	}
}

package Vehicles;
public class Sportscar extends Car
{

}

package Vehicles;

public class Main
{
	public static void main(String[] args)
	{
		Car myCar = new Car();
		myCar.Drive();

		Sportscar mySportsCar = new Sportscar();
		mySportsCar.Drive();

		Van myVan = new Van();
		myVan.Drive();

		Minivan myMiniVan = new Minivan();
		myMiniVan.Drive();

		ExcursionVan myExcursionVan = new ExcursionVan();
		myExcursionVan.Drive();
	}
}

package Vehicles;
public class Van extends Vehicle
{

}

package Vehicles;

public class Vehicle
{
	protected String make;
	protected String model;
	protected String year;

	public Vehicle()
	{
	}
	public Vehicle(String make, String model, String year)
	{
		this.make = make;
		this.model = model;
		this.year = year;
	}
	public final void setMake(String value)
	{
		make = value;
	}
	public final String getMake()
	{
		return make;
	}
	public final void setModel(String value)
	{
		model = value;
	}
	public final String getModel()
	{
		return model;
	}
	public final void setYear(String value)
	{
		year = value;
	}
	public final String getYear()
	{
		return year;
	}
	public final void Accelerate()
	{
	}
	public final void Decelerate()
	{
	}
	public final void Drive()
	{
	}
	public final void Start()
	{
	}
	public final void Stop()
	{
	}
}


Juan A. Ripoll - Programming Tutorials and Courses © 2024 All rights reserved.  Legal Conditions.