0% found this document useful (0 votes)
10 views

Programming Assignment 6

The document contains Java code defining interfaces and classes for vehicles including cars, trucks and motorcycles. The classes implement the interfaces to define attributes and behaviors of different vehicle types. A main program is defined to run the code but not implemented.

Uploaded by

josephmurindwa16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Programming Assignment 6

The document contains Java code defining interfaces and classes for vehicles including cars, trucks and motorcycles. The classes implement the interfaces to define attributes and behaviors of different vehicle types. A main program is defined to run the code but not implemented.

Uploaded by

josephmurindwa16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Programming Assignment Unit 6

University of the People

CS1102-01 Programming 1

Muhammad Murindwa

23 May 2024
public class Truck implements TruckVehicle {

private String make;

private String model;

private int year;

private double cargoCapacity;

private String transmissionType;

// Implement the constructor and other methods here

// Implementing methods from the Vehicle interface

public String getMake() {

return make;
}

public String getModel() {

return model;

public int getYear () {

return year;

public void setMake(String make) (

this.make = make;

public void setModel (String model) {

this.model = model;

public void setYear(int year) {

this.year = year;

// Implementing methods from the TruckVehicle interface

public double getCargoCapacity() {

return cargoCapacity;

}
public String getTransmissionType() {

return transmissionType;

public void setCargoCapacity(double capacity) {

this.cargoCapacity = capacity;

public void setTransmissionType(String transmissionType) {

this.transmissionType = transmissionType;

public class Motorcycle implements MotorVehicle {

private String make;

private String model;

private int year;

private int numberOfWheels;

private String motorcycle Type;

// Implement the constructor and other methods here

// Implementing methods from the Vehicle interface

public String getMake() {


return make;

public String getModel() {

return model;

public int getYear() {

return year;

public void setMake(String make) {

this.make = make;

public void setModel(String model) {

this.model = model;

public void setYear(int year) {

this.year = year;

// Implementing methods from the MotorVehicle interface

public int getNumberOfWheels() {

return numberOfWheels;
}

public String getMotorcycle Type() {

return motorcycleType;

public void setNumberOfWheels(int wheels) {

this.numberOfWheels = wheels;

public void setMotorcycleType(String type) {

this.motorcycleType = type;

public class Car implements CarVehicle {

private String make;

private String model;

private int year;

private int numberOfDoors;

private String fuelType;

// Implement the constructor and other methods here

// Implementing methods from the Vehicle interface

public String get Make() {


return make;

public String getModel() {

return model;

public int getYear() {

return year;

public void setMake(String make) {

this.make = make;

public void setModel (String model) {

this. model = model;

public void setYear(int year) {

this.year = year;

// Implementing methods from the Car Vehicle interface

public int getNumber OfDoors() {


return numberOfDoors;

public String getFuelTypel() {

return fuelType;

public void setNumberOfDoors(int doors) {

this.numberOfDoors = doors;

public void setFuelType(String fuelType) {

this.fuelType = fuelType;

public class MainProgram {

public static void main(String[] args) {

// Your main program logic here

public interface TruckVehicle extends Vehicle {

double getCargoCapacity();
String getTransmissionTypel();

void setCargoCapacity(double capacity);

void setTransmission Type(String transmissionType);

public interface MotorVehicle extends Vehicle {

int getNumberOfWheels();

String getMotorcycleType();

void setNumberOfWheels(int wheels);

void setMotorcycleType(String type);

public interface CarVehicle extends Vehicle {

int getNumberOfDoors();

String getFuelType();

void setNumberOfDoors(int doors):

void setFuelType(String fuelType);

public interface Vehicle {

String getMakel();

String getModel();

int getYear();

void setMake(String make);

void setModel(String model);


void setYear (int year);

Result:

Enter car make: Toyota

Enter car model: Camry

Enter car year: 2022

Enter number of doors: 4

Enter fuel type: Petrol

You might also like