Write a class called CheckingAccount that has the following fields and methods.
Fields
double balance
Methods
getBalance() - returns the balance as a double
withdraw(double amount) - withdraws amount if possible; otherwise, prints a message to the user saying, "Cannot complete withdraw: insufficient funds"
deposit(double amount) - adds the deposit amount to the balance
a constructor that takes an initial amount and initializes the balancefield.
public class Lab11Driver
{
public static void main(String[] args)
{
// Creates an account with a balance of $450.00
CheckingAccount c1=new CheckingAccount(450.00);
// Use the "getter" function to find the initial balance
double balance=c1.getBalance();
// Print it out
System.out.println("Your initial balance is: "+balance);
//Deposit $25.00
balance=c1.deposit(25.00);
// Should be $475.00
System.out.println("Your new balance is: "+balance);
//Withdraw $100.00
balance=c1.withdraw(100.00);
// Should be $375.00
System.out.println("Your new balance is: "+balance);
// Withdraw more than in the account
balance=c1.withdraw(9001.00);
//Should print -1, or some kind of error message
System.out.println("Your balance is: "+balance);
}
}