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

Tutorial 2

The document defines three classes - Vehicle, Car, and Bus. Vehicle is the parent class that defines common attributes like registration number and owner. Car extends Vehicle and adds an attribute for seat capacity. Bus also extends Vehicle and adds attributes for sitting capacity and standing capacity. Each class defines getters and setters for attributes and a toString method to return attributes in a formatted string.
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)
28 views

Tutorial 2

The document defines three classes - Vehicle, Car, and Bus. Vehicle is the parent class that defines common attributes like registration number and owner. Car extends Vehicle and adds an attribute for seat capacity. Bus also extends Vehicle and adds attributes for sitting capacity and standing capacity. Each class defines getters and setters for attributes and a toString method to return attributes in a formatted string.
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/ 5

1

Vehicle Class

package week3;

public class Vehicle {

private String noReg;

private String owner;

/**

* @param noReg

* @param owner

*/

public Vehicle(String noReg, String owner) {

setNoReg(noReg);

setOwner(owner);

public Vehicle() {

this("not set","not set");

/**

* @return the noReg

*/

public String getNoReg() {

return noReg;

/**

* @param noReg the noReg to set

*/

public void setNoReg(String noReg) {

this.noReg = noReg;
}

/**

* @return the owner

*/

public String getOwner() {

return owner;

/**

* @param owner the owner to set

*/

public void setOwner(String owner) {

this.owner = owner;

@Override

public String toString() {

return "("+getNoReg() + ") owned by " + getOwner();

Car Class

package week3;

public class Car extends Vehicle {

private int seatCapacity;

/**

* @param noReg

* @param owner

* @param seatCapacity

*/

public Car(String noReg, String owner, int seatCapacity


) {

super(noReg, owner);

setSeatCapacity(seatCapacity);

/**

* @return the seatCapacity

*/

public int getSeatCapacity() {

return seatCapacity;

/**

* @param seatCapacity the seatCapacity to set

*/

public void setSeatCapacity(int seatCapacity) {

this.seatCapacity = seatCapacity;

@Override

public String toString() {

return "Car ("+ super.toString() +" with seat capa"

+ "city " + getSeatCapacity() ;

Bus Class

package week3;

public class Bus extends Vehicle{

private int sittingCap;

private int standCap;


/**

* @param noReg

* @param owner

* @param sittingCap

* @param standCap

*/

public Bus(String noReg, String owner, int sittingCap,

int standCap) {

super(noReg, owner);

setSittingCap(sittingCap);

setStandCap(standCap);

/**

* @return the sittingCap

*/

public int getSittingCap() {

return sittingCap;

/**

* @param sittingCap the sittingCap to set

*/

public void setSittingCap(int sittingCap) {

this.sittingCap = sittingCap;

/**

* @return the standCap

*/

public int getStandCap() {

return standCap;

}
/**

* @param standCap the standCap to set

*/

public void setStandCap(int standCap) {

this.standCap = standCap;

@Override

public String toString() {

return "Bus ("+ super.toString() +" with sitting c"

+ "apacity: " + getSittingCap() + " and st"

+ "anding capacity: " + getStandCap

();

VehicleDriver class

Payment Class

You might also like