should already have this coded. We are going to enhance it by making the deposit
ID: 3737921 • Letter: S
Question
should already have this coded. We are going to enhance it by making the deposit and withdraw methods more realistic. You could not withdraw any amount of money if your balance was less than or equal to 0. You also could not deposit a negative amount. b. If you have it copy BankAccount to EnhancedBankAcount, If you no longer have the c. In the deposit method, check to see if the deposit is negative. If it is, then print "You cannot d. In the withdraw method, check to see if the balance the amount to withdraw is less than BankAccount class, copy the BankAccount class form page 94 and 95. make a negative deposit" and do not make the deposit. If it is not, make the deposit. Q. If it is then print "You do not have enough money to make the withdrawal". If it is not, make the withdrawal. e. Create a EpbancedBankAccouotTester by either copying the prior one or entering the code from the text on page 101. Make sure the reference to BankAccount is changed to f. g. Enter the code as it appears on page 101. Make a negative deposit. Make a withdrawal greater than the balance. Print the balance of batrxChecking account. h. Print the balance of bacccbeckog account. i. j.Explanation / Answer
First of all your question referring to the other parts of the your material/book, that we are not aware. But understood and answered with the inputs you have provided, Soultion is here
//Create EnhancedBankAccount.java file
public class EnhancedBankAccount {
int accountBalance;
public void deposit(int amount){
//Check if the amount entered is less than 0 or not !
if(amount<0){
System.out.println("You cannot make a negative deposit");
}else{
accountBalance = accountBalance + amount;
System.out.println("Amount "+amount+" deposited to account. current account balance is "+accountBalance);
}
}
public void withdraw(int amount){
//Check the amount entered is greater than account balance or not. to make withdraw
if((accountBalance-amount)<0){
System.out.println("You do not have enough money to make the withdrawl");
}
else{
accountBalance = accountBalance-amount;
System.out.println("Amount "+amount+" withdrawn from account. current account balance is "+accountBalance);
}
}
}
//Create EnhancedBankAccountTester.java file and run this make sure both files are in the same package. otherwise you have to import the class EnhancedBankAccount here.
public class EnhancedBankAccountTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
EnhancedBankAccount harryChecking = new EnhancedBankAccount();
//Trying to make negative deposit
harryChecking.deposit(-1000);
System.out.println("Harry current account Balance is "+harryChecking.accountBalance);
System.out.println("----------------------------------");
//Trying to do some deposit to the account
harryChecking.deposit(500);
System.out.println("Harry current account Balance is "+harryChecking.accountBalance);
System.out.println("----------------------------------");
//Trying with draw the amount more than the account balance
harryChecking.withdraw(800);
System.out.println("Harry current account Balance is "+harryChecking.accountBalance);
System.out.println("----------------------------------");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.