Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Please use java File Input Your program will accept a single argument on the command line, which is a non-empty string giving the name of

Please use java

File Input Your program will accept a single argument on the command line, which is a non-empty string giving the name of a file in the current directory. This file will contain descriptions of financial transactions. Each line of the file will contain one record of data. Each record will be represented by several strings, separated by slashes, in the following order: 1. An eight-digit integer representing the date on which the transaction was performed (e.g. 20040712). Date numbers will take the form yyyymmdd, where yyyy is the year number, mm is the month number (01-12), and dd is the day number (01-31). 2. An arbitrary string representing information on the type of transaction (e.g. check numbers, DEP for deposits, EFT for funds transfers, and so on). 3. A string representing a description of the transaction (e.g. payee of a check). 4. An integer representing the amount of the transaction in cents. Deposits are indicated by positive integers; withdrawals are indicated by negative integers. 5. The string true or false, indicating whether or not this transaction has been reconciled or not. Your program will begin by reading in this information and storing it internally in an appropriate format. (See Internal Requirements.)

Interactive Input Your program will then interact with the user running the program, offering the user a menu of commands. The following commands should be offered at this time: Search the database for a transaction. If selected, the program should ask the user for a string. Using that name, the program should display all transactions in the database whose descriptions contain that string. If no matching transactions can be found, an appropriate message should be displayed. Search the database for a date. If selected, the program should ask the user for an 8-digit date (in the same format used above). Using that date, the program should display all transactions in the database whose dates exactly match that date. If no matching transactions can be found, an appropriate message should be displayed.

Print the database. If selected, the program should print the entire contents of the database in an appropriate format. Compute balances. If selected, the program should print the sum of all transactions in the database (the current balance), as well as the sum of only the reconciled transactions in the database (the reconciled balance). Exit the program. If selected, the program should terminate. Internal Requirements As always, your program should use good style, as defined by the CS-102 Style Requirements handout. Your program should catch (and handle appropriately) all exceptions generated by any system routines you use, as well as any exceptions you generate yourself. (That is, your main method should not throw any exceptions.) Your program should be designed with modifiability in mind. You will be revising and extending this program several times throughout the semester; consequently, it is to your benefit to design your program in as modular a fashion as possible. In particular:

You should define a class Transaction which contains members corresponding to a given transaction, and methods which deal with airports (e.g. print, getDate).

You should define a class Database which contains methods which allow one to manipulate a collection of Transaction objects (e.g. search, print). The Database class should never access the internal members of the Transaction class directly; instead, it should use the public methods of the Transaction class for that purpose. For this assignment, your Database object should use an unordered array of Transaction objects. You should define the size of this array using a final constant and use that constant appropriately.

You should define a class Prog1 with a main method which interacts with the user and calls the Database class to perform the required operations. The Prog1 class should never access the internal members of the other classes directly. You will be replacing these classes several times through the semester as we learn about different data structures and algorithms. Thus, it is to your advantage to make your design as modular as possible. A little bit of extra work now will make your work simpler as the term progresses.

A Note on Currency The decision to represent currency amounts in the data file as an integer number of cents is deliberate. Floating-point variables (i.e., variables of type float or double) should never be used for this purpose. In many situations, fractional values stored in a floating-point variable cannot be represented exactly, only approximately. This can lead to problems as these approximation errors are allowed to propagate. Storing values as a whole number of cents in an integer variable avoids these problems entirely; the exact value of each transaction can be preserved without loss of precision. Of course, to print these values in traditional dollars-and-cents formats requires additional processing.

image text in transcribedimage text in transcribed

A Note on Currency The decision to represent currency amounts in the data file as an integer number of cents is deliberate. Floating-point variables (i.e., variables of type float or double) should never be used for this purpose. In many situations, fractional values stored in a floating-point variable cannot be repre- sented exactly, only approximately. This can lead to problems as these approximation errors are allowed to propagate. Storing values as a whole number of cents in an integer variable avoids these problems entirely; the exact value of each transaction can be preserved without loss of precision. Of course, to print these values in "traditional" dollars-and-cents formats requires additional processing A Sample Session Here is a sample data file which could be read by this program: 20040101/DEP/Initial Deposit/384102/true 20040301/EFT/Interest Earned/1095/true 20040305/1001/Pheasant Run Apartments (rent)/-85000/false 20040325/1002/Discover Card/-75690/true 20040315/DEP/Payday!/65046/false 20040303/ATM/Withdrawal (lunch)/-3000/true And here is a sample interactive session: Welcome to the CS-102 Checkbook Program Current available commands: 1 --> Search for a description 2 --> Search for a date 3 --> Print all transactions 4 --> Compute balance 9 --> Exit Your choice? 3 01 Jan 2004 (R) DEP 01 Mar 2004 (R) EFT 05 Mar 2004 ( 1001 25 Mar 2004 () 1002 15 Mar 2004 ) DP 03 Mar 2004 (R) ATM Initial Deposit Interest Earned Pheasant Run Apartments (rent) Discover Card Payday! Withdrawal (lunch) 3841.02 10.95 -850.00 -756.90 650.46 -30.00 Current available commands: 1 --> Search for a description 2 --> Search for a date 3 --> Print all transactions 4 --> Compute balance 9 --> Exit Your choice? 1 Enter string to search: Discover Card 25 Mar 2004 () 1002 Discover Card -756.90 Current available commands: 1 --> Search for a description 2 --> Search for a date 3 --> Print all transactions 4 --> Compute balance 9 --> Exit Your choice? 2 Enter date to search: 20040305 05 Mar 2004 () 1001 Pheasant Run Apartments (rent) -850.00 Current available commands: 1 --> Search for a description 2 --> Search for a date 3 --> Print all transactions 4 --> Compute balance 9 --> Exit Your choice? 4 Current Balance: 2865.53 Reconciled Balance: 3821.97 Current available commands: 1 --> Search for a description 2 --> Search for a date 3 --> Print all transactions 4 --> Compute balance 9 --> Exit Your choice? 9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions