oppgave: train
This commit is contained in:
@@ -9,7 +9,7 @@ package oving7.train;
|
||||
*/
|
||||
public class PassengerCar extends TrainCar {
|
||||
|
||||
// TODO: Add fields here
|
||||
private int passengerCount;
|
||||
|
||||
/**
|
||||
* Constructor for the passenger car.
|
||||
@@ -21,7 +21,7 @@ public class PassengerCar extends TrainCar {
|
||||
* @see PassengerCarTest#testWeight()
|
||||
*/
|
||||
public PassengerCar(int deadWeight, int passengerCount) {
|
||||
// TODO: Implement this constructor
|
||||
this.passengerCount = passengerCount;
|
||||
super(deadWeight);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@ public class PassengerCar extends TrainCar {
|
||||
* @see PassengerCarTest#testWeight()
|
||||
*/
|
||||
public int getPassengerCount() {
|
||||
// TODO: Implement this method
|
||||
return 0;
|
||||
return passengerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,22 +41,22 @@ public class PassengerCar extends TrainCar {
|
||||
* @see PassengerCarTest#testWeight()
|
||||
*/
|
||||
public void setPassengerCount(int passengerCount) {
|
||||
// TODO: Implement this method
|
||||
if (passengerCount < 0) {
|
||||
throw new IllegalArgumentException("passenger count cannot be less than zero");
|
||||
}
|
||||
this.passengerCount = passengerCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalWeight() {
|
||||
// To calculate the total weight of the passenger car, you can assume that an average
|
||||
// passenger weighs 80 kg
|
||||
|
||||
// TODO: Implement this method
|
||||
return 0;
|
||||
return super.getDeadWeight() + passengerCount * 80;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: Implement this method
|
||||
return null;
|
||||
return "PassengerCar";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user