Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Need in java source code 2. Create a Lab2Test class which, Requests the initi

ID: 641789 • Letter: 1

Question

1. Need in java source code

2. Create a Lab2Test class which,

Requests the initial balances for two separate accounts

Creates two account objects

Deposits money int the first account

Prints the current balance of that account

Repeat steps 3-5 with the second account

Sample Output (User input in bold)

Please enter the initial balance for account 103 567.25

Please enter the initial balance for account 207 1064.32

How much will you deposit in account 103? 281.00

How much will you withdraw from account 103? 193.67

The current balance in account 103 is 654.58

How much will you deposit in account 207? 338.34

How much will you withdraw from account 207? 274.99

the current balance in account 207 is 1127.67

I have some code but nothing works. I just want to start at the beggining. Please help.

Explanation / Answer

1. Account.java


public class Account {
private int id;
private double balance;
Account(){}
Account(int newID, double initialBalance)
{
setId(newID);
setBalance(initialBalance);
}
public int getId() {
   return id;
}
public void setId(int id) {
   this.id = id;
}
public double getBalance() {
   return balance;
}
public void setBalance(double balance) {
   this.balance = balance;
}

public void withdraw(double amount)
{
   balance=balance-amount;
}

public void deposit(double amount)
{
   balance=balance+amount;
}
}

2. Lab2Test.java

import java.util.*;
public class Lab2Test {


   public static void main(String[] args) {
       double am=0;  
Account a1=new Account(103,0.0);
Account a2=new Account(207,0.0);
Scanner s=new Scanner(System.in);
System.out.println("Please enter the initial balance for account"+a1.getId()+" ?");
am=s.nextDouble();
a1.setBalance(am);
System.out.println("Please enter the initial balance for account"+a2.getId()+" ?");
am=s.nextDouble();
a2.setBalance(am);
System.out.println("How much will you deposit in account "+a1.getId()+" ?");
am=s.nextDouble();
a1.deposit(am);
System.out.println("How much will you withdraw from account "+a1.getId()+" ?");
am=s.nextDouble();
a1.withdraw(am);
System.out.println("The current balance in account "+a1.getBalance());

System.out.println("How much will you deposit in account "+a2.getId()+" ?");
am=s.nextDouble();
a2.deposit(am);
System.out.println("How much will you withdraw from account "+a2.getId()+" ?");
am=s.nextDouble();
a2.withdraw(am);
System.out.println("The current balance in account "+a2.getBalance());
   }

}

The output is:---------------

Please enter the initial balance for account103 ?
567.25
Please enter the initial balance for account207 ?
1064.32
How much will you deposit in account 103 ?
281.00
How much will you withdraw from account 103 ?
193.67
The current balance in account 654.58
How much will you deposit in account 207 ?
338.34
How much will you withdraw from account 207 ?
274.99
The current balance in account 1127.6699999999998