Add oving 7

This commit is contained in:
Andreas Omholt Olsen
2026-03-06 10:59:33 +01:00
parent 6a27364518
commit 1deb0cc650
44 changed files with 1947 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
package oving7.abstractaccount;
/**
* A bank consists of many different types of accounts: credit accounts, debit accounts, savings
* accounts, etc. Since these have a lot in common, e.g. all have a balance, it is practical to
* collect as much of the common logic as possible in a superclass, which all can inherit from.
* However, this superclass is not a type of account in itself, and therefore we make it
* {@code abstract}, so that it cannot be instantiated. The concrete account classes that inherit
* from it, must of course be instantiable. The methods defined in the {@code AbstractAccount} class
* is similar to that of the Account interface in the SavingsAccount task.
*/
public abstract class AbstractAccountDocs {
// AbstractAccount has a state {@code balance} for the account balance. The balance should
// either be set to 0.0 by default or in the constructor
// TODO: Add fields and potentially a constructor here
/**
* Decreases the account balance by the specified amount. Note that the rules for withdrawals
* are different for the classes that implement {@code AbstractAccount}, and must therefore be
* implemented in each class.
*
* @param amount the amount to withdraw
* @throws IllegalArgumentException if the amount cannot be withdrawn
*/
// TODO: Define abstract method {@code void internalWithdraw} here
/**
* Increases the account balance by the specified amount.
*
* @param amount the amount to deposit
* @throws IllegalArgumentException if the amount is not positive
*/
public void deposit(double amount) {
// TODO: Implement this method
}
/**
* This method calls the {@link #internalWithdraw()} method, which is implemented in each
* subclass.
*
* @param amount the amount to withdraw
* @throws IllegalArgumentException if the amount is not positive
*/
public void withdraw(double amount) {
// TODO: Implement this method
}
/**
* @return the current balance of the account
*/
public double getBalance() {
// TODO: Implement this method
return 0.0;
}
}

View File

@@ -0,0 +1,50 @@
package oving7.abstractaccount;
/**
* A {@code CreditAccount} has in addition to {@code balance} a state for {@code creditLine}, i.e.
* available credit on the account. This credit line allows the account to be overdrawn (that the
* balance is negative) within the credit line. If {@link #internalWithdraw()} tries to withdraw
* more money than is available, taking the credit line into account, an
* {@code IllegalArgumentException} should be thrown.
*
* @see AbstractAccount
*/
public class CreditAccountDocs extends AbstractAccountDocs {
// TODO: Add fields here
/**
* Initializes a new {@code CreditAccount} with the specified credit line.
*
* @param creditLine the credit line
* @throws IllegalArgumentException if the credit line is negative
*/
public CreditAccountDocs(double creditLine) {
// TODO: Implement this constructor
}
// TODO: Override abstract method here
/**
* @return the credit line
*
* @see CreditAccountTest#testCreditLine()
*/
public double getCreditLine() {
// TODO: Implement this method
return 0.0;
}
/**
* Sets the credit line.
*
* @param creditLine the credit line
* @throws IllegalArgumentException if the credit line is negative
* @throws IllegalStateException if the new credit line does not cover the existing balance
*
* @see CreditAccountTest#testCreditLine()
*/
public void setCreditLine(double creditLine) {
// TODO: Implement this method
}
}

View File

@@ -0,0 +1,15 @@
package oving7.abstractaccount;
/**
* A debit account is the simplest form of account, where the only requirement is that the balance
* at any time must be greater than or equal to {@code 0.0}. {@code DebitAccount} extends (inherits
* from) {@link AbstractAccount} and ensure that the balance never falls below {@code 0.0}. If an
* attempt is made to withdraw more money than is available, an {@code IllegalArgumentException}
* should be thrown.
*
* @see AbstractAccount
*/
public class DebitAccountDocs extends AbstractAccountDocs {
// TODO: Override abstract method here
}

View File

@@ -0,0 +1,28 @@
package oving7.abstractaccount;
/**
* A {@code SavingsAccount} can only have a positive balance. In addition, the account has
* withdrawal restrictions. A {@code SavingsAccount} has {@code x} number of {@code withdrawals}. If
* you want to withdraw money after all withdrawals have been used up, the balance should be charged
* a {@code fee}. If the balance is too low to cover the fee, an {@code IllegalArgumentException}
* should be thrown.
*
* @see AbstractAccount
*/
public class SavingsAccountDocs extends AbstractAccountDocs {
// TODO: Add fields here
/**
* Initializes a new {@code SavingsAccount} with the specified number of withdrawals and fee.
*
* @param withdrawals the number of withdrawals
* @param fee the fee
* @throws IllegalArgumentException if the number of withdrawals or the fee is negative
*/
public SavingsAccountDocs(int withdrawals, double fee) {
// TODO: Implement this constructor
}
// TODO: Override abstract method here
}

View File

View File

@@ -0,0 +1,63 @@
package oving7.train;
/**
* One of two different types of train cars, both specialized versions for different purposes. A
* {@code CargoCar} represents a cargo car that transports various things and stuff.
*
* @see TrainCar
* @see PassengerCar
*/
public class CargoCarDocs extends TrainCarDocs {
// TODO: Add fields here
/**
* Constructor for the cargo car.
*
* @param deadWeight the weight of an empty cargo car
* @param cargoWeight the weight of the cargo in the cargo car
* @throws IllegalArgumentException if either deadWeight or cargoWeight is negative
*
* @see CargoCarTest#testWeight()
*/
public CargoCarDocs(int deadWeight, int cargoWeight) {
// TODO: Implement this constructor
super(deadWeight);
}
/**
* @return the weight of the cargo in the cargo car
*
* @see CargoCarTest#testWeight()
*/
public int getCargoWeight() {
// TODO: Implement this method
return 0;
}
/**
* @param cargoWeight the weight of the cargo in the cargo car
* @throws IllegalArgumentException if cargoWeight is negative
*
* @see CargoCarTest#testWeight()
*/
public void setCargoWeight(int cargoWeight) {
// TODO: Implement this method
}
@Override
public int getTotalWeight() {
// TODO: Implement this method
return 0;
}
@Override
public String toString() {
// TODO: Implement this method
return null;
}
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,66 @@
package oving7.train;
/**
* One of two different types of train cars, both specialized versions for different purposes. A
* {@code PassengerCar} represents a passenger car that transports passengers.
*
* @see TrainCar
* @see CargoCar
*/
public class PassengerCarDocs extends TrainCarDocs {
// TODO: Add fields here
/**
* Constructor for the passenger car.
*
* @param deadWeight the weight of an empty passenger car
* @param passengerCount the number of passengers in the passenger car
* @throws IllegalArgumentException if either deadWeight or passengerCount is negative
*
* @see PassengerCarTest#testWeight()
*/
public PassengerCarDocs(int deadWeight, int passengerCount) {
// TODO: Implement this constructor
super(deadWeight);
}
/**
* @return the number of passengers in the passenger car
*
* @see PassengerCarTest#testWeight()
*/
public int getPassengerCount() {
// TODO: Implement this method
return 0;
}
/**
* @param passengerCount the number of passengers in the passenger car
* @throws IllegalArgumentException if passengerCount is negative
*
* @see PassengerCarTest#testWeight()
*/
public void setPassengerCount(int passengerCount) {
// TODO: Implement this method
}
@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;
}
@Override
public String toString() {
// TODO: Implement this method
return null;
}
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,81 @@
package oving7.train;
/**
* The class {@code Train} represents a train that consists of one or more train cars.
*
* @see TrainCar
* @see CargoCar
* @see PassengerCar
*/
public class TrainDocs {
// TODO: Add fields here
/**
* @param trainCar the train car to check for
* @return {@code true} if the train contains the train car, {@code false} otherwise
*
* @see TrainTest#testAddCarToTrain()
*/
public boolean contains(TrainCar trainCar) {
// TODO: Implement this method
return false;
}
/**
* Adds a train car to the train.
*
* @param trainCar the train car to add
* @throws IllegalArgumentException if the train car is {@code null}
*
* @see TrainTest#testAddCarToTrain()
*/
public void addTrainCar(TrainCar trainCar) {
// TODO: Implement this method
}
/**
* @return the sum of the total weight of all the train cars in the train. There is no need to
* take the weight of the locomotive into account
*
* @see TrainTest#testTotalTrainWeight()
*/
public int getTotalWeight() {
// TODO: Implement this method
return 0;
}
/**
* @return similar to {@link PassengerCar#getPassengerCount()}, but for the entire train
*
* @see TrainTest#testPassengerCount()
*/
public int getPassengerCount() {
// TODO: Implement this method
return 0;
}
/**
* @return similar to {@link CargoCar#getCargoWeight()}, but for the entire train
*
* @see TrainTest#testCargoWeight()
*/
public int getCargoWeight() {
// TODO: Implement this method
return 0;
}
/**
* @return a string representation of the train. The string should consist of the
* {@link #toString()}s of all train cars in the train
*/
@Override
public String toString() {
return null;
}
// TODO: Write a main method to test the class
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,71 @@
package oving7.train;
/**
* The class {@code TrainCar} represents a simple and general train car.
*/
public class TrainCarDocs {
// TODO: Add fields here
/**
* Constructor for a train car.
*
* @param deadWeight the weight of an empty train car
* @throws IllegalArgumentException if deadWeight is negative
*
* @see TrainCarTest#testDeadWeight()
*/
public TrainCarDocs(int deadWeight) {
// TODO: Implement this constructor
}
/**
* @param deadWeight the weight of an empty train car. In other words, the weight of only the
* carriage, without passengers and cargo
* @throws IllegalArgumentException if deadWeight is negative
*
* @see TrainCarTest#testDeadWeight()
*/
public void setDeadWeight(int deadWeight) {
// TODO: Implement this method
}
/**
* @return the weight of an empty train car. In other words, the weight of only the carriage,
* without passengers and cargo
*
* @see TrainCarTest#testDeadWeight()
*/
public int getDeadWeight() {
// TODO: Implement this method
return 0;
}
/**
* @return the total weight of the train car. Note that this method should also be callable on
* subclasses and still return the total weight of the train car (keyword:
* redefinition).
*
* @see TrainCarTest#testDeadWeight()
*/
public int getTotalWeight() {
// TODO: Implement this method
return 0;
}
/**
* @return a string representation of the train car. The string should contain the type of the
* train car and the total weight of the train car. For {@link PassengerCar}, the number
* of passengers should also be included. For {@link CargoCar}, the weight of the cargo
* should also be included.
*/
@Override
public String toString() {
// TODO: Implement this method
return null;
}
public static void main(String[] args) {
}
}