Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i have my own using java, i want to solve a problem in which is myTestCases.txt is not printed all movements from my program. Everything
i have my own using java, i want to solve a problem in which is myTestCases.txt is not printed all movements from my program. Everything in the program works, but that is the only thing i have an issue, i want to print on that file for example: N John Doe Savings
W
B
I
X
D
I
W
this is my code: import java.ioFile;
import java.ioFileNotFoundException;
import java.ioIOException;
import java.ioPrintWriter;
import java.util.Scanner;
public class pgmHW
Constants
final static int MINACCOUNT ;
final static int MAXACCOUNT ;
final static int MAXNUM ;
public static void mainString args throws IOException
Variable declarations
BankAccount account new BankAccountMAXNUM;
int numAccts; Number of accounts
char choice; Menu item selected
boolean notDone true; Loop control flag
Open input test cases file
File testFile new FilemyTestCasestxt;
Scanner testScanner new ScannertestFile;
Create Scanner object for user input
Scanner kybd new ScannerSystemin;
Open the output file
PrintWriter outFile new PrintWriterpgmOutputtxt;
First part: fill and print initial database
numAccts readAcctsaccount;
printAcctsaccount numAccts, outFile;
Second part: process transactions
do
menu;
choice kybdnextcharAt; Read user input character
kybdnextLine; Consume the newline character
switch choice
case q:
case Q:
notDone false;
printAcctsaccount numAccts, outFile;
break;
case b:
case B:
balanceaccount numAccts, outFile, kybd;
break;
case i:
case I:
accountInfoaccount numAccts, outFile, kybd;
break;
case d:
case D:
depositaccount numAccts, outFile, kybd;
break;
case w:
case W:
withdrawalaccount numAccts, outFile, kybd;
break;
case n:
case N:
numAccts newAcctaccount numAccts, outFile, kybd;
break;
case x:
case X:
numAccts deleteAcctaccount numAccts, outFile, kybd;
break;
default:
outFile.printlnError: choice is an invalid selection try again";
outFile.println;
outFile.flush;
break;
while notDone;
Close the output file
outFile.close;
Close the test cases input file
kybdclose;
System.out.println;
System.out.printlnThe program is terminating";
Method readAccts
Input:
account reference to array of Bank Accounts
Process:
Reads the initial database of accounts and balances
Output:
Fills in the initial account and balance arrays and returns the number of active accounts
private static int readAcctsBankAccount account throws FileNotFoundException
open database input file
create File object
File dbFile new FilebcciscpgmschapterprjBankAccountsinitAccountstxt;
File dbFile new FileinitAccountstxt;
create Scanner object
Scanner sc new ScannerdbFile;
int count ; account number counter
int maxAccts account.length; maximum number of active accounts allowed
while schasNext && count maxAccts
try
Depositor depositornew Depositornew NamescnextscnextscnextInt;
BankAccount tmpAccnew BankAccountdepositorscnextIntAccountType.valueOfscnexttoUpperCasescnextDouble;
if tmpAccgetAccountNumber MINACCOUNT && tmpAcc.getAccountNumber MAXACCOUNT
accountcount tmpAcc;
count;
catch Exception es
esprintStackTrace;
close the input file
scclose;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started