Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, Implement a function called customer dictionary with a single parameter balfilename, the name of the file containing current account balance information for the

In Python,

  1. Implement a function called customer dictionary with a single parameter balfilename, the name of the file containing current account balance information for the customers of the bank in the format described above The function should open balfilename for reading. It should then create a dictionary with key:value pairs in which the key is the bank account number of a customer, and the value associated with a key is a list con- taining the SSN and the account balance for that customer. The function must return the dictionary. Remember to close the file prior to the return statement.

  2. Implement a function called update customer dictionary with two parameters. The first parameter, cdictionary, is the customer dictionary described above. The second parameter, transfilename, is the name of the file containing all the transactions for all the customers at the bank in the format described above This function should open transfilename for reading, and then update the cdictionary to include all the deposits and withdrawals for each customer. Recall that the value associated with each customer is a list. Hence, the deposits and the withdrawals for a customer can be recorded as additional entries in the list. Remember to close the file after it has been read completely.

  3. Implement a function called new balance files to create the two output files described above. This function has three parameters: The first parameter, cdictionary, is the customer dictionary described above. The second parameter, summfilename, is the name of the file containing the transaction summaries for the customers of the bank. The third parameter, newbalfilename, is the name of the file containing the new account balance information for all the customers. As noted above, the output files created by this function should be neatly formatted.

image text in transcribed

image text in transcribed

Problem 2 [25 points ) Bank Transactions. For this problem, you will write a program to do some basic file processing to carry out some banking transactions for the customers of a bank. Assume for our purposes that each customer has exactly one account at the bank. The bank maintains two files of data. One file contains account balance information for each customer of the bank. Each line of this file contains three data items: A customer's social security number (SSN), the bank account number, and the balance at the end of the previous business period this might be a month, a week, or a day, but the actual length of the business period is not relevant for our purposes). The SSN is a string of digits in the usual format xxx-xx-xxxx, the bank account number is simply a three digit number (unique to each customer), and the balance is a floating point value. The second file contains all the bank transactions that have taken place in the current business period for all the customers at the bank. Each line of this file contains just two data items: a bank account number and the dollar amount of the transaction. If the transaction is a deposit, it is indicated as a positive value and if it is a payment (withdrawal), it is indicated as a negative value. A customer's bank account number may appear several times in the file (if they had several transactions during the business period) or may not appear at all (if they did not carry out any transactions at the bank during the business period). A transaction is simply recorded at the time that it takes place, hence the account numbers may appear in any order in the file and all the transactions for a particular account may not appear together (that is, on consecutive lines) in the file. The goal is to update each customer's bank balance information by taking into account all transactions (deposits as well as withdrawals) that have taken place in the current business period. If the resulting account balance is greater than $3000, a 2% interest on the new account balance) is added on. If the resulting account balance is less than $100, a $10 penalty is applied to the account. Your program must create two files. One file should contain transaction summaries for all the customers of the bank. It should contain, for each customer, their account number, SSN, the old balance, total of all deposits made, total of all withdrawals made, the interest amount added, the penalty added, and the final new balance. The second file is the file containing the new account balance information (the bank will eventually replace the old account balance file with this one). Each line of this file should contain the customer's SSN, bank account number, and the new balance at the end of the current business period. All of the data in the output files should be formatted nicely. In particular, the bank account number and SSN should be printed left-justified in appropriately chosen field widths. All dollar amounts should be printed right-justified, with a precision of 2, in appropriately chosen field widths. For the purposes of formatting, you may assume that bank balances are always below $100,000. The columns in the output file should be given appropriate headings as well (see sample files below). The above task will be accomplished by using a dictionary to keep track of a customer's transactions for the current business period, as specified in the following three functions: 1. Implement a function called customer-dictionary with a single parameter balfilename, the name of the file containing current account balance information for the customers of the bank in the format described above The function should open balfilename for reading. It should then create a dictionary with key:value pairs in which the key is the bank account number of a customer, and the value associated with a key is a list con- taining the SSN and the account balance for that customer. The function must return the dictionary. Remember to close the file prior to the return statement. 2. Implement a function called update customer dictionary with two parameters. The first parameter, cdictionary, is the customer dictionary described above. The second parameter, transfilename, is the name of the file containing all the transactions for all the customers at the bank in the format described above This function should open transfilename for reading, and then update the cdictionary to include all the deposits and withdrawals for each customer. Recall that the value associated with each customer is a list. Hence, the deposits and the withdrawals for a customer can be recorded as additional entries in the list. Remember to close the file after it has been read completely. 3. Implement a function called new balance files to create the two output files described above. This function has three parameters: The first parameter, cdictionary, is the customer dictionary described above. The second parameter, summfilename, is the name of the file containing the transaction summaries for the customers of the bank. The third parameter, newbalfilename, is the name of the file containing the new account balance An example is provided below. Consider the following example of the file containing account balance information: 100 300 123-45-6789 345-23-1782 672-39-1929 819-00-7810 700 348.17 3029.25 1800.87 -50.25 900 Suppose the file containing transactions data is the following file: 900 150.25 100 525.72 100 -150.75 300 -500.00 100 -27.38 300 -550.00 900 -120.00 300 2400.00 300 -300.00 Then the output file containing transaction summaries should look like this: ACCOUNT# SSN PREV BAL DEPOSITS WITHDRAWALS INTEREST PENALTY NEW BAL 100 300 123-45-6789 345-23-1782 672-39-1929 819-00-7810 348.17 3029.25 1800.87 -50.25 525.72 2400.00 0.00 150.25 178.13 1350.00 0.00 120.00 0.00 81.58 0.00 0.00 0.00 0.00 10.00 695.76 4160.83 1800.97 -30.00 700 900 0.00 10.00 The output file containing the new account balance information should look like this: 123-45-6789 345-23-1782 672-39-1929 819-00-7810 100 300 700 900 695.76 4160.83 1800.97 -30.00

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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions