Question
Using Java Jcreator please edit the program below to prompt the user to Enter a deposit amount after the intial balances are displayed. import java.util.Scanner;
Using Java Jcreator please edit the program below to prompt the user to "Enter a deposit amount" after the intial balances are displayed.
import java.util.Scanner;
class AccountTest
{
public static void main(String[] args)
{
account account1 = new account("Emily Smith", 50.00);
account account2 = new account("John Doe", -7.53);
displayAccount(account1);
displayAccount(account2);
Scanner input=new Scanner(System.in);
double depositAmount=input.nextDouble();
System.out.printf("%nadding %.2f" "to account1 balance%n%n", depositAmount);
account1.deposit(depositAmount);
displayAccount(account1);
displayAccount(account2);
System.out.print("Enter deposit amount for account2: ");
depositAmount = input.nextDouble();
System.out.printf("%nadding %.2f to account2 balance%n%n", depositAmount);
account2.deposit(depositAmount); //add to account2 balance
displayAccount(account1);
displayAccount(account2);
} //End main
public static void displayAccount(account accountToDisplay)
{
System.out.printf("%s balance: $%.2f%n",accountToDisplay.getName(),accountToDisplay.getBalance());
}
}
class account
{
private String name;
private double balance;
public account(String name, double balance)
{
this.name=name;
if(balance>0.0)
this.balance=balance;
}
public void deposit(double depositAmount)
{
if(depositAmount>0.0)
balance=balance+depositAmount;
}
public void withdrawl(double withdrawlAmount)
{
if(balance>withdrawlAmount)
{
balance=balance-withdrawlAmount;
}
else
System.out.println("Withdrawl amount exceeded account balance");
}
public double getBalance()
{
return balance;
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started