import java.util.*; public class BankAccount { private int accountNumber; privat
ID: 3732645 • Letter: I
Question
import java.util.*;
public class BankAccount {
private int accountNumber;
private String ownerName;
private double balance;
private String type;
public BankAccount() {
accountNumber = 0;
ownerName = "";
balance = 0.0;
type = "Personal";
}
public BankAccount(int number, String name, double initialDeposit, String type) {
accountNumber = number;
ownerName = name;
balance = initialDeposit;
this.type = type;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int number) {
accountNumber = number;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String name) {
ownerName = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double newAmount) {
balance = newAmount;
}
public String getType() {
return type;
}
public void deposit(double amount) {
balance += amount;
}
public void withdrawl(double amount) {
balance -= amount;
}
public String toString() {
return type + ": " + accountNumber + " " + ownerName + " " + balance;
}
}
In a different Java class, called ClientUpdate.java, create a bank's client processing program with the following specifications The single client's file contains information on all that person's accounts (personal, business and charitable), including deposits, withdrawals, interest earned and charges. These are all stored in a text file, the name of the file should be input from the keyboard The first line of the file contains an integer, called number, indicating the number of accounts and the client's name The next number lines of the file contain, for each account, a String token indicating the type of the account and a unique integer representing the account number and a real number indicating the starting balance o o An array of BankAccounts can be created to hold the client file information. Use a constructor from the BankAccount class to instantiate each of the accounts Following that, there are an unknown number of lines, each contains the integer identification number for the account, a String (one of "deposit", "withdrawal", "interest", "charge") indicating the type of transaction, and a real number indicating the amount of the transaction o The amount of a deposit must be added to the BankAccount's balance; The amount of a withdrawl must be subtracted from the balance . The amount of interest requires adding 'amount' % interest to the account; * The amount of a (service) charge must be subtracted from the account. Use member methods of the BankAccount class to alter the attributes of the appropriate BankAccount object Once the entire file has been processed output all attributes of each account to the screen Use the instance method called toString ()to make a single String containing all attributes of a BankAccount object that is being printed oExplanation / Answer
JAVA PROGRAM WITH COMMENTS:
import java.util.
public class BankAccount {
private int accountNumber;//instance variable to hold account number
private String ownerName;//instance variable to hold owner name
private double balance; //instance variable to hold balance
private String type; // Personal, Business, Charitable. instance variable to hold account type
public BankAccount() { //default constructor
accountNumber = 0;//Initialising with value 0
ownerName = "";//Initialising with value ""
balance = 0.0;//Initialising with value 0.0
type = "Personal";//Initialising with value "Personal"
}
public BankAccount(int number, String name, double initialDeposit, String type) {//Parameterised constructor
accountNumber = number;
ownerName = name;
balance = initialDeposit;
this.type = type; // Why does 'this' need to be used here?? this.type indicates instance variable. type indicates contructor parameter
}
public int getAccountNumber() {//get method to return account number
return accountNumber;
}
public void setAccountNumber(int number) {//set method to set account number
accountNumber = number;
}
public String getOwnerName() {//get method to return owner name
return ownerName;
}
public void setOwnerName(String name) {//set method to set owner name
ownerName = name;
}
public double getBalance() {//get method to return balance
return balance;
}
public void setBalance(double newAmount) {//Set method to set amount
balance = newAmount;
}
public String getType() {//get method to return account type
return type;
}
public void deposit(double amount) {//method to add account amount
balance += amount;
}
public void withdrawl(double amount) {//method to remove amount
balance -= amount;
}
public String toString() {//method to return the class properties
return type + ": " + accountNumber + " " + ownerName + " " + balance;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.