package inheritance;

public class PassengerCar extends TrainCar {

  private int passengerCount;
  private static int passengerWeight = 80;

  public PassengerCar(int deadWeight, int passengerCount) {
    super(deadWeight);
    this.setPassengerCount(passengerCount);
  }

  public int getPassengerCount() {
    return this.passengerCount;
  }

  public void setPassengerCount(int passengerCount) {
    if (passengerCount < 0)
      throw new IllegalArgumentException("Passenger count cannot be less than 0");
    this.passengerCount = passengerCount;
  }

  private int getTotalPassengerWeight() {
    return this.getPassengerCount() * passengerWeight;
  }

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

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