user12292617
user12292617

Reputation:

Java banking system problems

I'm making a banking system based on an UML that I got recently. I'm having problems finishing some methods, whereas I tried several things to complete it myself.

It's the following. My method "addInterest()" isn't adding any sort of interest to the balance that one account has. May it be checking account or savings account. it just doesn't add it.

And one more question, in the requirements it's being said that after every new customer has been made, 2 accounts are being made. I hope i've done it correctly, and some correction would be highly appreciated! I know that the code isn't 100% complete yet, but i'm doing it bit by bit.

Account.java

package com.company;

public class Account {
    public static Double interest = 0.042;
    private static Long number = 0L;
    private Double balance = 0.0;

    public Account(Double interest, Long number, Double balance) {

        number = Account.number;
        balance = this.balance;
    }


    public void deposit(Integer amount) {

        balance = balance + amount;

    }

    public double addInterest() {
        return balance += balance * interest;
    }

    public double getBalance() {

        return balance;

    }

    public static void main(String[] args) {
        Account checkingaccount = new Account(interest, 1L, 0.0);
        Account savingsaccount = new Account(interest, 1L, 0.0);

        Customer customer = new Customer(1L, "John Doe", savingsaccount, checkingaccount);


        checkingaccount.deposit(500);
        savingsaccount.deposit(100);


        checkingaccount.addInterest();
        savingsaccount.addInterest();

        System.out.println("Has a balance of " + checkingaccount.getBalance());

        System.out.println("Has a balance of " + savingsaccount.getBalance());

        System.out.println("Total balance is " + customer.totalBalance());



    }
}

Customer.java

class Customer {
    private static Long lastNumber;
    private String name;
    private Account savingsAccount;
    private Account checkingAccount;


public Customer(Long lastNumber, String name, Account savingsAccount, Account checkingAccount){
    //add lastnumber
    this.name = name;
    this.savingsAccount = savingsAccount;
    this.checkingAccount = checkingAccount;
}

public String getName(){
    return this.name;
}

public Account getCheckingaccount(Account checkingaccount){
    return checkingaccount;
}

//public Long getUniqueNumber(){
//
//}

public Account getSavingsaccount(Account savingsaccount){
    // return savingsAccount info
    return savingsaccount;
}

public double totalBalance(){
    // return totalbalance
    return savingsAccount.getBalance() + checkingAccount.getBalance();
}

















}

Upvotes: 0

Views: 368

Answers (1)

dimo414
dimo414

Reputation: 48874

You don't appear to be calling addInterest() in your main() method or elsewhere. You might want to call it inside .deposit() or after both .deposit() calls in main(). It depends on how you want the Account to behave (e.g. most banks add interest on a given timeline, such as once a month).

Upvotes: 1

Related Questions