Need ClientUpdate.java In a different Java class, called ClientUpdate.java, crea
ID: 3735006 • Letter: N
Question
Need ClientUpdate.java
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
Please find the code below with detailed inline comments.
CODE
=======================
public class ClientUpdate {
public static void main(String[] args) {
BufferedReader br = null;
FileReader fr = null;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the file name : ");
String fileName = sc.next();
try {
//br = new BufferedReader(new FileReader(FILENAME));
fr = new FileReader(fileName + ".txt");
br = new BufferedReader(fr);
String firstLine = br.readLine();
String in[] = firstLine.split(" ");
int number = Integer.parseInt(in[0]);
String ownerName = in[1];
BankAccount[] accounts = new BankAccount[number];
for(int i=0; i<number; i++) {
String type;
int accNumber;
double balance;
String line = br.readLine();
String splits[] = line.split(" ");
type = splits[0];
accNumber = Integer.parseInt(splits[1]);
balance = Double.parseDouble(splits[2]);
accounts[i] = new BankAccount(accNumber, ownerName, balance, type);
}
String line;
while((line = br.readLine()) != null) {
String splits[] = line.split(" ");
int accNo = Integer.parseInt(splits[0]);
String transaction = splits[1];
double amount = Double.parseDouble(splits[2]);
for(int i=0; i<number; i++) {
if(accounts[i].getAccountNumber() == accNo) {
if("deposit".equalsIgnoreCase(transaction)) {
accounts[i].setBalance(accounts[i].getBalance() + amount);
}
} else if(accounts[i].getAccountNumber() == accNo) {
if("withdrawal".equalsIgnoreCase(transaction)) {
accounts[i].setBalance(accounts[i].getBalance() - amount);
}
} else if(accounts[i].getAccountNumber() == accNo) {
if("interest".equalsIgnoreCase(transaction)) {
accounts[i].setBalance(accounts[i].getBalance() * (1 + amount));
}
} else if(accounts[i].getAccountNumber() == accNo) {
if("service".equalsIgnoreCase(transaction)) {
accounts[i].setBalance(accounts[i].getBalance() - amount);
}
}
}
}
System.out.println("The Bank Accounts details are: " );
for(int i=0; i<number; i++) {
System.out.println(accounts[i]);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.