Task

Your task is to write a PHP program that simulates a very simple ATM (Automatic Teller Machine).

The input to your program will consist of two plain-text files: acct.txt and tranz.txt

acct.txt will contain current balances for a number of bank accounts in the following format:

< INT account ID> < FLOAT balance>

For example:

101 345.23
102 43.2
103 0
104 33

tranz.txt will contain a ledger of tranactions (Deposits/Withdrawals) that you will need to apply against the corresponding accounts. Each transaction will be on a separate line and will be in the following format:

< INT account ID> < CHAR transaction type> < FLOAT amount>

For example:

ID Type(D,W) Amount
105 D 200
108 W 500.55
101 D 45.12
102 D -555

Please note, the first line of this file is the header and should be ignored. Define and use a class called Account - write its definition in a file called Account.php.

Write a PHP program that reads account information from acct.txt and creates account objects. Then reads and applies transactions to them as specified by tranz.txt; name the main file for this program index.php.

Once processing is finished, store updated balances in update.txt in the same format as acct.txt.

If a transaction is invalid (invalid transaction type - anything other than D or W, invalid amount or the account does not have sufficient balance), then nothing is to be changed. Account class should raise a custom exception BadTranzException defined in BadTranzException.php that should be caught in index.php. On catching such an exception, you will create a new object of type BadTranz (which you will define in BadTranz.php). This object should contain information about the transaction (acc ID, type, amount) and the reason why it is a bad transaction.

At the end of the program, output the following information in a structured way, using HTML (to be viewed in a browser):

a) Total number of transactions (as recorded in tranz.txt)
b) Total number of valid transactions
c) A table containing each invalid transaction and the reason for it being invalid

Example output:

There were 28 transactions in total.
There were 21 valid transactions.
The following transactions are invalid:

Line # ID Type Amount Reason
2 108 W 500.55 Insufficient Balance
4 102 D -555 Negative Transaction Amount
7 999 W 35 Invalid Account ID

Place all your code in a namespace based on your name and subnamespace A1, e.g. jdoe\A1.

All class files should be loaded by a PSR-4 compliant autoloader that you are to write. You can use the example provided as part of PSR-4 as a starting point:

github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

Place all class files inside src/A1/ subdirectory. Project root should only contain autoloader.php and index.php (that will require the autoloader.php). You can place all the txt files into the project root as well.

Hint: Do not use '' or / for directory separators in paths defined in your autoloader. This will make your code incompatible with other operating systems. Use PHPs predefined constant DIRECTORY_SEPARATOR that will be equal to the appropriate directory separator for the operating system that is executing the code.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.