Using Java Consider a class that represents a bank account. a. Such a class migh
ID: 3814500 • Letter: U
Question
Using Java Consider a class that represents a bank account. a. Such a class might store information about the account balance, the name of the account holder, and an account number. What instance variables would you declare to hold this information? Give a type and name for each. b. There are a number of operations that would make sense for a bank account—withdraw money, deposit money, check the balance, and so on. Write a method header with return type, name, and parameter list, for each such operation described below. Don’t write the whole method—just the header. They will all be public methods. The first one is done for you as an example. i. Withdraw a given amount from the account. This changes the account balance, but does not return a value. public void withdraw(double amount) ii. Deposit a given amount into the account. This changes the account balance, but does not return a value. iii. Get the balance from the account. This does not change anything in the account; it simply returns the balance. iv. Return a string containing the account information (name, account number, balance). This does not change anything in the account. v. Charge a $ 10 fee. This changes the account balance but does not return a value. vi. Create a new account given an initial balance, the name of the owner, and the account number. Note that this will be a constructor, and that a constructor does not have a return type.
Explanation / Answer
public class bankAccount {
public double accountBalance;
public String accountHolder;
public long accountNumber;
public double getAccountBalance() {
return accountBalance;
}
public void setAccountBalance(double accountBalance) {
this.accountBalance = accountBalance;
}
public String getAccountHolder() {
return accountHolder;
}
public void setAccountHolder(String accountHolder) {
this.accountHolder = accountHolder;
}
public long getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(long accountNumber) {
this.accountNumber = accountNumber;
}
public bankAccount(double accountBalance, String accountHolder,
long accountNumber) {
super();
this.accountBalance = accountBalance;
this.accountHolder = accountHolder;
this.accountNumber = accountNumber;
}
public void withdraw(double amount) {
//write the calculation for money withdrawal
}
public void deposit(double amount) {
//write the calculation for money depositing
}
public double getBalance(long accountNumber) {
double balance = 0.0;
//write the calculation for money withdrawal
return balance;
}
@Override
public String toString() {
return "bankAccount [accountBalance=" + accountBalance
+ ", accountHolder=" + accountHolder + ", accountNumber="
+ accountNumber + "]";
}
public double chargeFees(long accountNumber, double feeCharged) {
double balance = 0.0;
feeCharged = 10.0;
//write the calculation for money withdrawal
return balance;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.