
Gm A.
asked 02/07/21Java code required
UBL bank provides income statements to its account holders upon their request on monthly basis. An Income statement includes the accountholder's account number, account tftle, total debft, total credit, transactionID, transactionDate, DebitAmount, CreditAmount, etc. You need to develop a comprehensive and bugs free Java program In which all mentioned information should store on a text file. Encapsulate your program in a try-catch block to handle possible exceptions. After storing the text file, write a piece of code for reading that particular text file.
1 Expert Answer

Patrick B. answered 02/07/21
Math and computer tutor/teacher
//Account.java
class Account
{
protected String accountNum;
protected String accountName;
protected double totalDebit;
protected double totalCredit;
public Account( String acctNum, String acctName, double debitTotal, double creditTotal)
{
this.accountNum = new String(acctNum);
this.accountName = new String(acctName);
this.totalDebit = debitTotal;
this.totalCredit =creditTotal;
}
public Account(String acctNum, String acctName)
{
this.accountNum = new String(acctNum);
this.accountName = new String(acctName);
this.totalDebit = this.totalCredit =0;
}
public Account() { accountNum=accountName=null; totalDebit=totalCredit=0; }
public Account(Account account)
{
this.accountNum = new String(account.accountNum);
this.accountName = new String(account.accountName);
this.totalDebit = account.totalDebit;
this.totalCredit = account.totalCredit;
}
public String GetAccountNum() { return(accountNum); }
public String GetAccountName() { return(accountName); }
public double GetTotalDebit() { return(totalDebit); }
public double GetTotalCredit() { return(totalCredit); }
public void SetTotalDebit( double debitTotal) { totalDebit = debitTotal ; }
public void SetTotalCredit( double creditTotal) { totalCredit = creditTotal; }
public String SerializeToCSV()
{
return(
new String(
accountNum + "," + accountName + "," + totalDebit + "," + totalCredit
)
);
}
public Account( String csvBuff)
{
String tokens[] = csvBuff.split(",");
this.accountNum = new String(tokens[0]);
this.accountName = new String(tokens[1]);
this.totalDebit = Double.parseDouble(tokens[2]);
this.totalCredit = Double.parseDouble(tokens[3]);
}
}
//Transaction.java
class Transaction
{
protected String accountNum;
protected int transID;
protected String transDate;
protected double debitAmount;
protected double creditAmount;
public Transaction (String acctNum, int idSeqNum, String dateTimeStamp, double debit, double credit)
{
this.accountNum = new String(acctNum);
this.transID = idSeqNum;
this.transDate = new String(dateTimeStamp);
this.debitAmount = debit;
this.creditAmount = credit;
}
public Transaction() { accountNum=transDate=null; transID=0; debitAmount=creditAmount=0; }
public String GetAccountNum() { return(accountNum); }
public int GetTransID() { return(transID); }
public String GetTransDate() { return(transDate); }
public double GetDebitAmount() { return(debitAmount); }
public double GetCreditAmount() { return(creditAmount); }
public String SerializeToCSV()
{
return (
new String(
accountNum + "," + transID +"," + transDate + "," + debitAmount + "," + creditAmount
)
);
}
public Transaction(Transaction transaction)
{
this.accountNum = new String(transaction.accountNum);
this.transID = transaction.transID;
this.transDate = new String(transaction.transDate);
this.debitAmount = transaction.debitAmount;
this.creditAmount = transaction.creditAmount;
}
public Transaction(String csvBuff)
{
String tokens[] = csvBuff.split(",");
this.accountNum = new String(tokens[0]);
this.transID = Integer.parseInt(tokens[1]);
this.transDate = new String(tokens[2]);
this.debitAmount = Double.parseDouble(tokens[3]);
this.creditAmount = Double.parseDouble(tokens[4]);
}
}
//Bank.java
import java.io.*;
class Bank
{
private Account accounts[];
private Transaction transactions[];
private int numAccounts;
private int numTransactions;
public int Open()
{
int iReturn=0;
String inbuff;
try
{
FileReader fileReader = new FileReader("E:\\accounts.dat");
BufferedReader bufferedReader = new BufferedReader(fileReader);
inbuff = bufferedReader.readLine();
this.numAccounts = Integer.parseInt(inbuff.trim());
accounts = new Account[this.numAccounts];
for (int iLoop=0; iLoop<this.numAccounts; iLoop++)
{
inbuff = bufferedReader.readLine();
accounts[iLoop] = new Account(inbuff);
}
bufferedReader.close();
fileReader = new FileReader("E:\\transactions.dat");
bufferedReader = new BufferedReader(fileReader);
inbuff = bufferedReader.readLine();
this.numTransactions = Integer.parseInt(inbuff.trim());
transactions = new Transaction[this.numTransactions];
for (int iLoop=0; iLoop<this.numTransactions; iLoop++)
{
inbuff = bufferedReader.readLine();
transactions[iLoop] = new Transaction(inbuff);
}
bufferedReader.close();
}
catch (IOException ex)
{
iReturn = -1;
}
return(iReturn);
}
public void Report()
{
for (int accountLoop=0; accountLoop<this.numAccounts; accountLoop++)
{
String curAccountNum = accounts[accountLoop].GetAccountNum();
System.out.println("Account #:" + curAccountNum);
System.out.println("Account name:" + accounts[accountLoop].GetAccountName());
System.out.println("Total debit:" + accounts[accountLoop].GetTotalDebit());
System.out.println("Total credit:" + accounts[accountLoop].GetTotalCredit());
System.out.println(" transID trans Date debit credit \n");
for (int transLoop=0; transLoop<this.numTransactions; transLoop++)
{
if (curAccountNum.compareTo(transactions[transLoop].GetAccountNum())==0)
{
System.out.print(transactions[transLoop].GetTransID() + " ");
System.out.print(transactions[transLoop].GetTransDate() + " ");
System.out.print(transactions[transLoop].GetDebitAmount() + " ");
System.out.println(transactions[transLoop].GetCreditAmount());
}
}
System.out.println("----------------------------------------------------");
}
}
public static void main(String args[])
{
Bank bank = new Bank();
if (bank.Open()>=0)
{
bank.Report();
}
}
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code posted in the RESROUCES section under this link02/07/21