I need help coding a python program that simulates an ATM at a small bank, allowing customers to make various transactions?

The task is to simulate an ATM at a small bank, allowing customers to make various transactions. The 

file “P://Courses//CPSC//CPSC207//bankers.txt” contains the last names, PINs, and current balances for 

each customer. The information for each customer is all on one line, separated by commas. Your program 

should read in the data from this file. Once this is completed it should prompt the user for their name. If the 

name is in the list, they will then be prompted to enter their PIN. If a matching name and PIN is entered, 

then they should be allowed to make a transaction. They should be able to check their current balance, make 

a deposit, or make a withdrawal. The withdrawal should only be allowed if they have sufficient funds. 

The program should allow multiple users to use the ATM without rerunning the program each time. So, 

after each transaction is completed, the program should continue running and again prompt the user for 

their name. Allow the user to indicate somehow that the program should stop running (perhaps by entering 

“done” as we did in a previous example). Once it is indicated that the program should terminate, print the 

names and balances for all customers to verify that your program worked successfully. 

This program will make use of object oriented programming. Your program should include a definition 

for a new class called Customer. You should define an init method, an str method, as well as any 

other methods you want to include. 

1 Answer

  • 8 months ago

    Don't try to write this all at once.  Start by defining a Customer class and some methods you're sure you'll need, such as get_balance(), deposit() and withdraw().  It will be handy if your __init__() method accepts all of the values from the text file: name, PIN and initial balance.

    You'll have to decide how to respond to a .withdraw() method call where the amount is negative or is larger than the current balance.  Some options are to:

        - return a boolean result, True if the operation succeeded or False if not

        - raise an exception (ValueError, for example)

        - return the new balance if the operation succeeded, or None if not

    Then work on a function that will read customer data from a text file and return a collection of Customer objects created from the lines of the file.  Probably the best built-in data type for the collection is a dictionary, with an all-lower-case version of the customer name as a key and the corresponding  Customer object as the value.  You can convert a list of customers to a that type of dictionary with something like:

        customers = {} # empty dictionary to start

        for cust in customer_list:

            customers[cust.get_name().lower()] = cust

    To find if a customer name is in the list, you can use:

        if name.lower() in customers:

            ... it's a good name; Customer object is customers[name.lower()]


            ... bad customer name

    I'd get those working before starting any work on the user interface.

    One final note for now: When you get to writing the login section, you'll need to code the login according to the given specification--but that spec has a common error in it.  Secure login designs will always ask for both the login name and password before verifying either.  Remember that for anything you write later, but for this assignment you'll need to validate the user name (see above) before prompting for a password.

Still have questions? Get answers by asking now.