Object-Oriented Implementation of Python ATM Script: Where Did I Go Wrong?

In summary, to make object-oriented code you need to create a class for each object you want to represent, define attributes for each object, and provide methods for each object.
  • #1
sedat96
1
0
hello everyone,
I am a new member of this forum I found really good topics and good community that helps with many scientific fields. So I have this long text-based user interface for banking system written in python functions , but needs to be written using object oriented programming. I had build many possible structures without reading the implementations of the instructor, but as I read them and try to apply them everything become very complicated.

How can write/re-write the following code(ready) using the objected oriented Python? : http://www.pastebin.ca/3751103

Where did i make a mistake?Here i tried the whole last weak something like this:
http://pastebin.ca/3751105


finally, here are the implementations :http://pastebin.ca/3751108THANKS all and happy new year.
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Just putting everything into a single class doesn't make the code object-oriented.

Start with a list of objects you want to have. An account, for example. What are the properties of an account? What are things an account can do? Certainly not printing a navigation menu, as your current code suggests! And why do you define an Admin as "some type of account"?
 
  • #3
sedat96 said:
hello everyone,
I am a new member of this forum I found really good topics and good community that helps with many scientific fields. So I have this long text-based user interface for banking system written in python functions , but needs to be written using object oriented programming. I had build many possible structures without reading the implementations of the instructor, but as I read them and try to apply them everything become very complicated.

How can write/re-write the following code(ready) using the objected oriented Python? : http://www.pastebin.ca/3751103

Where did i make a mistake?Here i tried the whole last weak something like this:
http://pastebin.ca/3751105


finally, here are the implementations :http://pastebin.ca/3751108THANKS all and happy new year.
Your second link contains the following:
Implementation Notes:
 You need to create a class to represent a User. It should have type of user (may be one of
“regular”, “admin”), user name, and password as its attributes.
 You need to create a class to represent an Account. It should have user, balance, and
transactions as its attributes. User attribute should be an instance of the User class.
Transactions attribute should be a list which keeps the past user transactions where each
transaction should be an instance of the Transaction class. Whenever an operation is
performed by the user in the below-listed class methods, a new transaction should be
added properly. It should provide the following methods:
o deposit
o withdraw
o transfer
o get_latestN_transactions
 You need to create a class to represent a Transaction. It should have type, amount,
additional_info as attributes. additional_info attribute should be dictionary where the key
should be type/name of some additional info (e.g., ‘recipient’ in transfer transactions) and
the value would be the value of that information field (e.g., the recipient’s name in
transfer transactions). It is up to you to add methods into this class.
 You need to create a class which will represent a Bank. It will have a dictionary of
accounts as an attribute where dictionary will store all accounts as objects (i.e., key would
be account holder’s user name and value would be an Account instance). It should
provide the following methods:
o create_account
o close_account
o compute_and_print_statistics
o load_accounts_from_file
o search_for_an_account2 | P a g e
 You need to create a class which will represent a MenuEntry. Each option on any menu
that you provide to the user will be an instance of MenuEntry class. It will have
option_number and text as its attributes.
 You need to create another class which will represent a Menu. It will have a list of
MenuEntry objects. In your interface, you have four different menus (regular main menu,
admin menu, the small menu that you show after each operation for regular users, and the
small menu that you show after each operation for admin user). Each of these menus
should be represented as separate Menu objects. Menu class should provide the following
methods:
o add_menu_entry – this method should take a text for the new menu entry as
input, and create a new instance of MenuEntry object with the provided text.
Option_number of the new menu item object should be assigned automatically
based on the current size of the Menu. For instance, if the menu currently
contains 1 entry, the new MenuEntry will have option_number 2.
o print_menu_and_get_user_selection – this method should print the menu as
in previous project, ask the user to make a selection, handle any invalid selections
that the user may do, and return the selection option number to the caller.
These notes lay out pretty clearly what you need to do: create a number of classes with the specified properties.
 
Last edited by a moderator:
  • #4
Mark44 said:
Your second link contains the following:

These notes lay out pretty clearly what you need to do: create a number of classes with the specified properties.
man , how can i delete this thread ? thanks in advance
 
  • #5
Our policy is to not delete such threads when there have been replies to the question.
 
Back
Top