Answered step by step
Verified Expert Solution
Link Copied!

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 151515 John Doe 987654321 Savings 150.00
W 15151550.00
B 161616
I 987654321
X 161616
D 777777200.00
I 999999
W 234567700.00
this is my code: import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class pgmHW2{
// Constants
final static int MIN_ACCOUNT =100000;
final static int MAX_ACCOUNT =999999;
final static int MAX_NUM =100;
public static void main(String[] args) throws IOException {
// Variable declarations
BankAccount[] account = new BankAccount[MAX_NUM];
int numAccts; // Number of accounts
char choice; // Menu item selected
boolean notDone = true; // Loop control flag
// Open input test cases file
File testFile = new File("myTestCases.txt");
Scanner testScanner = new Scanner(testFile);
// Create Scanner object for user input
Scanner kybd = new Scanner(System.in);
// Open the output file
PrintWriter outFile = new PrintWriter("pgmOutput.txt");
// First part: fill and print initial database
numAccts = readAccts(account);
printAccts(account, numAccts, outFile);
// Second part: process transactions
do {
menu();
choice = kybd.next().charAt(0); // Read user input character
kybd.nextLine(); // Consume the newline character
switch (choice){
case 'q':
case 'Q':
notDone = false;
printAccts(account, numAccts, outFile);
break;
case 'b':
case 'B':
balance(account, numAccts, outFile, kybd);
break;
case 'i':
case 'I':
accountInfo(account, numAccts, outFile, kybd);
break;
case 'd':
case 'D':
deposit(account, numAccts, outFile, kybd);
break;
case 'w':
case 'W':
withdrawal(account, numAccts, outFile, kybd);
break;
case 'n':
case 'N':
numAccts = newAcct(account, numAccts, outFile, kybd);
break;
case 'x':
case 'X':
numAccts = deleteAcct(account, numAccts, outFile, kybd);
break;
default:
outFile.println("Error: "+ 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
kybd.close();
System.out.println();
System.out.println("The 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 readAccts(BankAccount[] account) throws FileNotFoundException {
// open database input file
//create File object
//File dbFile = new File("/bc/cisc3115/pgms/chapter_00/prj00_01BankAccounts/initAccounts.txt");
File dbFile = new File("initAccounts.txt");
//create Scanner object
Scanner sc = new Scanner(dbFile);
int count =0; //account number counter
int maxAccts = account.length; //maximum number of active accounts allowed
while (sc.hasNext() && count maxAccts)
{
try {
Depositor depositor=new Depositor(new Name(sc.next(),sc.next()),sc.nextInt());
BankAccount tmpAcc=new BankAccount(depositor,sc.nextInt(),AccountType.valueOf(sc.next().toUpperCase()),sc.nextDouble());
if (tmpAcc.getAccountNumber()>= MIN_ACCOUNT && tmpAcc.getAccountNumber()= MAX_ACCOUNT){
account[count]= tmpAcc;
count++;
}
}catch (Exception es)
{
es.printStackTrace();
}
}
//close the input file
sc.close();
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago