NOTE The completed code must pass in the following compiler
NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=bj4cc&problem=ch03/c03_exp_3_103
PLEASE also make sure of the following:
-Post this as text, not as an image.
-Avoid making alterations to the original code unless necessary.
-Post the complete, passing output- from the this compiler specifically- as evidence this code was accepted and passed.
~
Implement a BankAccount that pays a bonus of $10 for each new account.
Complete the following code:
The following class is used to check your work:
Solution
BankAccountTester.java
//The following class is used to check your work:
public class BankAccountTester
{
public static void main(String[] args)
{
BankAccount account1 = new BankAccount();
System.out.println(\"Balance: \" + account1.getBalance());
System.out.println(\"Expected: 10\");
BankAccount account2 = new BankAccount(1000);
System.out.println(\"Balance: \" + account2.getBalance());
System.out.println(\"Expected: 1010\");
}
}
BankAccount.java
public class BankAccount
{
private double balance;
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
// your work here
balance = 10;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
// your work here
balance = initialBalance + 10;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}
Output:
Balance: 10.0
Expected: 10
Balance: 1010.0
Expected: 1010

