package inheritance;

public class CargoCar extends TrainCar {

  private int cargoWeight;

  public CargoCar(int deadWeight, int cargoWeight){
    super(deadWeight);
    this.setCargoWeight(cargoWeight);
  }

  public int getCargoWeight() {
    return this.cargoWeight;
  }

  public void setCargoWeight(int cargoWeight) {
    if (cargoWeight < 0)
      throw new IllegalArgumentException("Cargo weight cannot be less than 0");
    this.cargoWeight = cargoWeight;
  }

  @Override
  public int getTotalWeight() {
    return this.getDeadWeight() + this.getCargoWeight();
  }

  @Override
  public String toString() {
    return String.format(
      "(Cargo w:%d, cw:%d)",
      this.getTotalWeight(),
      this.getCargoWeight()
    );
  }
}

