Erin S.

asked • 11/28/17

Java code bank account and test account using currency formater

Bank Account complied with no errors and I think I have my code correct for TestAccount. Assignment details and code below. I NEED HELP PLEASE!
 
Create a class named BankAccount with data fields for account number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required $200.00 minimum for an account. Include a method that displays the account details, including an explanation if the balance was reduced to 0.
Write the class TestAccount in which you instantiate two BankAccount objects, prompt a user for values of the account number and the balance, and then display the values for each field in each account object. Make sure to format the balance output as currency, with the “$" sign and values of dollars and cents (use Java currency formatter). Save both classes as BankAccount.java and TestAccount.java.
 
// a bank account has a balance and an owner who can make deposits
// Owner can all make withdrawals from the account
import java.util.Scanner;

public class BankAccount
{
//instance variables
private double balance = 0.0;
private String owner = "NoName";

// this is default constructor for a bank account with zero balance
public BankAccount(){}
// initial balance = the initial balance
// name = name of account owner

public BankAccount(double initialBalance, String name)
{
balance = initialBalance;
owner = name;
}
//method for depositing money to the bank account
//damount the amount to be deposited

public void deposit(double dAmount)
{
balance = balance + dAmount;
}
//method for withdrawing moeny from the bank account
// wamount = the amount to be withdrawn
public void withdraw(double wAmount)
{
balance = balance - wAmount;
}
// method for getting the current balance of the bank account
// return the current balance

public double getBalance()
{
return balance;

}

}
 
 
import java.Scanner;
import java.text.NumberFormat;
import java.util.Locale;
// main method for testing the bank account//

public class TestAccount
{
public static void main(String[]args)
{
BankAccount testAccount = new BankAccount();
testaccount.deposit(100);
testaccount.withdraw(50);

Scanner scanner = new scanner(System.in);
System.out.println(testaccount.owner + " Please enter your deposit amount");
double deposit = scanner.nextDouble();
System.out.println(testAccount.owner + " Please enter your withdrawal amount");
double withdraw = scanner.nextDouble();
System.out.println(testAccount.owner + " 's account has a balance of $" + testAccount.balance);


Locale unitedstatesLocale = new Locale(" $USD ");
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);

{
if(balance + dAmount >= 200 )
{
balance = balance + dAmount;

if(balance - wAmount >= 200 )
{
balance = balance -wAmount;
}
else
System.out.println(aBalance + " Your account balance is less than $200.00 and will be set to $0.00 avaiable");
{
return balance;
System.out.println("$USD" + us.format(balance));

}

}

1 Expert Answer

By:

Larry C. answered • 11/28/17

Tutor
4.9 (294)

Computer Science and Mathematics professional

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.