Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8/1/2018 Setup Your Java Files Abstract a zip file a Key + public Additional Req

ID: 3920062 • Letter: 8

Question

8/1/2018 Setup Your Java Files Abstract a zip file a Key + public Additional Requirements . Vehicle class: - The model of vehicle (e g. Corolla, Dungfeng. Panther). Empty string by default. The model should be stored in -getCategory is an abstract method and represents the type of the vehicle. -Format returned by toString "Model: .Truck class: cargoCapacity is an integer representing cargo capacity of the truck. getCategory returns the category of the Truck based on its cargoCapacity. If capacity is less or equal to 3300, its LIGHT WEIGHT, between 3300 and 6000 (inclusive) its MEDIUM, and above 6000 is HEAVY DUTY Constructors and toString should invoke appropriate counterparts in parent class. Format returned by toString: Model :

Explanation / Answer

Note : Plz let me know if u need any changes in this. Thank You

________________

Vehicle.java

public abstract class Vehicle {

private String model = "";

public Vehicle(String model) {

setModel(model);

}

public String getModel() {

return model;

}

public void setModel(String model) {

this.model = model.toUpperCase();

}

public abstract String getCategory();

@Override

public String toString() {

return "Model : " + getCategory();

}

public boolean isMidRange() {

if (model.equals("MEDIUM"))

return true;

else

return false;

}

}

________________

Car.java

public class Car extends Vehicle {

private int noofSeats = 1;

public Car(String model, int noofSeats) {

super(model);

this.noofSeats = noofSeats;

}

public int getNoofSeats() {

return noofSeats;

}

public void setNoofSeats(int noofSeats) {

this.noofSeats = noofSeats;

}

@Override

public String getCategory() {

if (noofSeats < 3)

return "SMALL";

else if (noofSeats >= 3 && noofSeats <= 5)

return "MEDIUM";

else

return "FAMILY";

}

@Override

public String toString() {

return super.toString() + " Category :" + getCategory()

+ " noofseats : " + noofSeats;

}

}

_______________

Truck.java

public class Truck extends Vehicle {

private int cargoCapacity;

public Truck(String model, int cargoCapacity) {

super(model);

this.cargoCapacity = cargoCapacity;

}

public int getCargoCapacity() {

return cargoCapacity;

}

public void setCargoCapacity(int cargoCapacity) {

this.cargoCapacity = cargoCapacity;

}

@Override

public String getCategory()

{

if(cargoCapacity<=3300)

return "LIGHT WEIGHT";

else if(cargoCapacity>=3300 && cargoCapacity<=6000)

return "MEDIUM";

else

return "HEAVY DUTY";

}

@Override

public String toString() {

return super.toString() + " Category :" + getCategory()

+ " Cargo Capacity : " + cargoCapacity;

}

}

_________________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote