#C14227. Banking System Simulator
Banking System Simulator
Banking System Simulator
This problem requires you to simulate a basic banking system for a single customer. The system supports a number of operations including deposit, withdraw, check_balance, transfer, apply_interest, calculate_loan_emi, and view_transaction_history. For the calculate_loan_emi operation, the EMI is computed using the formula: $$ EMI = P \times \frac{r_{monthly}(1+r_{monthly})^{n_{months}}}{(1+r_{monthly})^{n_{months}} - 1} $$ where \(P\) is the loan amount, \(r_{monthly}\) is the monthly interest rate (i.e. annual rate divided by 12 and 100) and \(n_{months}\) is the total number of months. Negative amounts for deposit or withdrawal should be rejected with the appropriate error. The operations are processed sequentially and some operations may result in an immediate output (for example, calculating EMI or viewing the transaction history).
inputFormat
The input consists of two lines read from stdin:
- The first line contains a floating point number representing the initial balance.
- The second line is a JSON array representing a list of operations. Each operation is a JSON object that includes an
operation
field and additional fields as required:- deposit: requires an
amount
field (float). - withdraw: requires an
amount
field (float). - check_balance: no extra fields.
- transfer: requires an
amount
field (float). - apply_interest: no extra fields (applies a fixed annual interest rate of 3%).
- calculate_loan_emi: requires
amount
,annual_rate
, andtenure_years
fields. - view_transaction_history: returns the history of previous deposit, withdraw, or transfer operations.
- deposit: requires an
outputFormat
The output is written to stdout and can either be a JSON object or an error string. For most operations, the JSON object includes final_balance
and transaction_history
fields. For the calculate_loan_emi
operation, the JSON object includes an emi
field. Errors are output as plain strings.## sample
100
[{"operation": "deposit", "amount": 50}]
{"final_balance":150,"transaction_history":[{"operation":"deposit","amount":50}]}