Object-Oriented Programming with Java, part I – Exercise 72.3

This program creates three accounts and then transfers money in between them.

My Code

public class Accounts {

    public static void main(String[] args) {
        // Code in Account.Java should not be touched!
        // write your code here
        Account aAccount = new Account("A",100.00);
        Account bAccount = new Account("B",0.00);
        Account cAccount = new Account("C",0.00);
        
        transfer(aAccount, bAccount, 50.00);
        transfer(bAccount, cAccount, 25.00);

    }
    
    public static void transfer(Account from, Account to, double howMuch){
        from.withdrawal(howMuch);
        to.deposit(howMuch);
    }


}

Model Code

public class Accounts {

 

    public static void main(String[] args) {

        // Code in Account.Java should not be touched!

        // write your code here

        Account tiliA = new Account("tili A", 100.0);

        Account tiliB = new Account("tili B", 0.0);

        Account tiliC = new Account("tili C", 0.0);

 

        transfer(tiliA, tiliB, 50);

        transfer(tiliB, tiliC, 25);

    }

 

    public static void transfer(Account form, Account to, double amount) {

        form.withdrawal(amount);

        to.deposit(amount);

    }

 

}

Comments

Still prefer my code. Not because it does anything different but I think it follows the instructions more carefully.

Leave a comment