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
}