Embed presentation
Download to read offline
![import java.util.Scanner;
public class AccountFrame
{
public static void main(String args[])
{
Account account1 = new Account (50.00);
Account account2 = new Account(-7.53);
System.out.printf("account1 balance:$%.2fn".account1.getBalance());
System.out.printf("account2 balance:$
%.2fnn".account2.getBalance());
Scanner input= new Scanner(System.in);
double depositAmount;
System.out.printf("enter deposit amount for account1:");
depositAmount = input.nextDouble();
System.out.printf("nadding %.2f to account1
balancenn".depositAmount);
account1.credit(depositAmount);
System.out.printf("account1 balance: $
%.2fn".account1.getBalance());
System.out.printf("account2 balance: $
%.2fnn".account2.getBalance());
System.out.printf("enter deposit amount for account2:");
depositAmount =input.nextDouble();
System.out.printf("nadding %.2f to account2
balancenn".depositAmount);
account2.credit(depositAmount);
System.out.printf("account1 balance: $
%.2fn".account1.getBalance());
System.out.printf("account2 balance: $
%.2fn".account2.getBalance());
}
}](https://image.slidesharecdn.com/test-140312072348-phpapp01/75/Jva-1-2048.jpg)

This Java code defines two Account objects with initial balances, allows user input of deposit amounts to add to each account balance, and prints the updated balances. It creates two Account objects, prints their initial balances, prompts the user to enter deposit amounts for each account, deposits those amounts to the accounts by calling the credit method, and prints the new balances.
![import java.util.Scanner;
public class AccountFrame
{
public static void main(String args[])
{
Account account1 = new Account (50.00);
Account account2 = new Account(-7.53);
System.out.printf("account1 balance:$%.2fn".account1.getBalance());
System.out.printf("account2 balance:$
%.2fnn".account2.getBalance());
Scanner input= new Scanner(System.in);
double depositAmount;
System.out.printf("enter deposit amount for account1:");
depositAmount = input.nextDouble();
System.out.printf("nadding %.2f to account1
balancenn".depositAmount);
account1.credit(depositAmount);
System.out.printf("account1 balance: $
%.2fn".account1.getBalance());
System.out.printf("account2 balance: $
%.2fnn".account2.getBalance());
System.out.printf("enter deposit amount for account2:");
depositAmount =input.nextDouble();
System.out.printf("nadding %.2f to account2
balancenn".depositAmount);
account2.credit(depositAmount);
System.out.printf("account1 balance: $
%.2fn".account1.getBalance());
System.out.printf("account2 balance: $
%.2fn".account2.getBalance());
}
}](https://image.slidesharecdn.com/test-140312072348-phpapp01/75/Jva-1-2048.jpg)