Exercises Java with Examples-
Practice Exercises Java 4,5 5 302940

Vehicles - Practice Exercises Java


Lesson 6:

Object oriented programming


Exercise 6.4:

Vehicles


Objetive:

Using Visual Studio, 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".


Source 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()
	{
	}
}
Exercisey 6.4

Share Now:


Google Ads





Privacy Policy:



Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.

Cookies

This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.