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

This program creates two accounts and then removes 100 from one of them, deposits it in the other and prints both.

My Code

public class Accounts {

    public static void main(String[] args) {
        // Code in Account.Java should not be touched!
        // write your code here
        Account mattsAccount = new Account("Matt's account",1000.00);
        Account myAccount = new Account("My account",0.00);
        mattsAccount.withdrawal(100);
        myAccount.deposit(100);
        System.out.println(mattsAccount);
        System.out.println(myAccount);
    }

}

Model Code

public class Accounts {

 

    public static void main(String[] args) {

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

        // write your code here

        Account accoutOfMatt = new Account("Matt's account", 1000.0);

        accoutOfMatt.withdrawal(100);

        Account myAccount = new Account("My account", 0.0);

        myAccount.deposit(100);

 

        System.out.println(accoutOfMatt);

        System.out.println(myAccount);

    }

 

}

Comments

Basically the same although I prefer mine as the accounts are created in one section and the balances changed separately.

Leave a comment