oppgave: train
This commit is contained in:
@@ -5,7 +5,7 @@ package oving7.train;
|
||||
*/
|
||||
public class TrainCar {
|
||||
|
||||
// TODO: Add fields here
|
||||
private int deadWeight;
|
||||
|
||||
/**
|
||||
* Constructor for a train car.
|
||||
@@ -16,7 +16,10 @@ public class TrainCar {
|
||||
* @see TrainCarTest#testDeadWeight()
|
||||
*/
|
||||
public TrainCar(int deadWeight) {
|
||||
// TODO: Implement this constructor
|
||||
if (deadWeight < 0) {
|
||||
throw new IllegalArgumentException("dead weight cannot be less than zero");
|
||||
}
|
||||
this.deadWeight = deadWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +30,10 @@ public class TrainCar {
|
||||
* @see TrainCarTest#testDeadWeight()
|
||||
*/
|
||||
public void setDeadWeight(int deadWeight) {
|
||||
// TODO: Implement this method
|
||||
if (deadWeight < 0) {
|
||||
throw new IllegalArgumentException("dead weight cannot be less than zero");
|
||||
}
|
||||
this.deadWeight = deadWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,8 +43,7 @@ public class TrainCar {
|
||||
* @see TrainCarTest#testDeadWeight()
|
||||
*/
|
||||
public int getDeadWeight() {
|
||||
// TODO: Implement this method
|
||||
return 0;
|
||||
return deadWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,8 +54,7 @@ public class TrainCar {
|
||||
* @see TrainCarTest#testDeadWeight()
|
||||
*/
|
||||
public int getTotalWeight() {
|
||||
// TODO: Implement this method
|
||||
return 0;
|
||||
return deadWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +65,7 @@ public class TrainCar {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: Implement this method
|
||||
return null;
|
||||
return "TrainCar";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user