oppgave: train

This commit is contained in:
2026-03-23 18:36:37 +01:00
parent fd661adfc5
commit 3f7ea46a2f
8 changed files with 56 additions and 39 deletions
+12 -9
View File
@@ -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) {