Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

EXPLAIN the strategic importance of technology in HRM.

Answered: 1 week ago