package inheritance;


public class TrainCar {
  private int deadWeight;

  public TrainCar(int deadWeight) {
    this.setDeadWeight(deadWeight);
  }

  public int getTotalWeight() {
    return deadWeight;
  }

  public void setDeadWeight(int deadWeight) {
    if (deadWeight < 0)
      throw new IllegalArgumentException("Deadweight cannot be less than 0");
    this.deadWeight = deadWeight;
  }

  public int getDeadWeight() {
    return this.deadWeight;
  }  

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


