A bank account consists of an integer for the account number, a string for the a
ID: 3889141 • Letter: A
Question
A bank account consists of an integer for the account number, a string for the account owner, a floating-point account balance, and a floating-point interest rate You can assume the constructor and standard "getter" and "setter" methods are already defined. Your job is to write the specification for two methods: 1. The Withdraw method subtracts a client-specified amount of money from the account, and indicates whether or not the request was successful (for example, if the client program tries to withdraw an amount greater than the account balance, it would not work). 2. The Addlnterest) method calculates the interest gained for the month and adds that amount to the account balance. The new account balance is returned to the calling code Your job is to write the specification for these two methods. You do not have to implement the actual logic of these methods, but you should supply a complete method signature and comments indicating purpose, precondition, postcondition, argument descriptions, and return value descriptionExplanation / Answer
please find the bank account class in java
import java.util.Scanner;
public class TestBankAccount {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
float withdraw;
BankAccount acc = new BankAccount("John",1234, 1234, 3);
System.out.println("Account holder name "+ acc.getAccholderName());
System.out.println("Account number "+ acc.getAccNo());
System.out.println("Current Balance "+ acc.getBalance());
System.out.println();
System.out.print("Enter amount to withdraw: ");
withdraw = sc.nextFloat();
if(acc.withdraw(withdraw))
System.out.println("New balance after withdraw is "+acc.getBalance());
else
System.out.println("You don't have sufficient balance in the account");
System.out.println("Updated money after monthy interest is "+acc.AddInterest());
}
}
class BankAccount{
int accNo;
String accholderName;
float balance;
float intRate;
public int getAccNo() {
return accNo;
}
public void setAccNo(int accNo) {
this.accNo = accNo;
}
public String getAccholderName() {
return accholderName;
}
public void setAccholderName(String accholderName) {
this.accholderName = accholderName;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
public float getIntRate() {
return intRate;
}
public void setIntRate(float intRate) {
this.intRate = intRate;
}
public BankAccount(String name, int no, float bal, float rate){
this.accholderName = name;
this.accNo = no;
this.balance = bal;
this.intRate = rate;
}
public boolean withdraw(float withdrawMoney) {
if(withdrawMoney > balance)
return false;
this.balance = this.balance - withdrawMoney;
return true;
}
public float AddInterest(){
this.balance = this.balance + (this.balance * intRate)/12;
return balance;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.