Question
15. Given the following program: public class Bank { public static void main (String[] args){ BankAccount myAccount = new BankAccount(); myAccount.deposit(200); myAccount.withdraw(150); System.out.println(Your balance is:
15. Given the following program:
public class Bank {
public static void main (String[] args){
BankAccount myAccount = new BankAccount();
myAccount.deposit(200);
myAccount.withdraw(150);
System.out.println(Your balance is: + myAccount.getBalance() );
}
}
Complete the BankAccount class outlined below by filling in the method bodies based on the comments:
public class BankAccount {
private double balance;
/**
Increase the balance of the bank account by the amount specified in 'amount' but only if amount is greater than zero.
*/
public void deposit (double amount){
}
/**
Decrease the balance of the bank account by the amount specified in 'amount' but only if the operation would not result in a negative balance
*/
public void withdraw (double amount){
}
/**
Return the current balance of the bank account
*/
public double getBalance (){
}
}
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