Hello, everybody! For Assignment6, we are going to design a banking system using object-oriented programming and Python.
Our banking system will consist of at least the following entities:
We expect that you will turn in one file: a Bank.py
file which contains your object-oriented code.
This assignment will give you an opportunity to think creatively and also implement concrete code. It will probably be helpful to refer back to lecture 14, in which we explored object-oriented programming. Think about what entities your system will include, as well as which attributes each class will need. In particular, think about the relationships between entities: what pairs of entities demonstrate "has-a" relationships and what entities demonstrate "is-a" relationships (see the lecture notes for how to code these up!). Remember: one of the goals of CS253, and of great software engineering, is having a vision for the "big picture" (i.e., this kind of design) as well as the granular details.
In Python, setting up a class looks like this:
class Bank: def __init__(self, attribute, num=100): self.attribute = attribute self.number = num def bank_method(self, num): result = self.number + num return result # other methods and class attributes
A couple of notes about the above code:
__init__(self)
method is called an initializer. If you have worked with Java or C++ before,
you might be familiar with the concept of a constructor instead; for our purposes these are the same thing (but just
know that technically they are different things). A Python initializer establishes the state (meaning, all of the variables and methods
as well as their values) when a Python object is instantiated (which is a fancy word to mean, "made an instance of").
self
refers to the object itself, and needs to be passed as an argument to every method belonging to the class.
num=num
or plain arguments in the function definitions, same as writing
Python functions, which you are already used to.
# to instantiate a class, assign an instance of that class to a variable, which looks like this syntactically b = Bank("Daniel's Bank") # based on the code above, I pass in the string "Daniel's Bank" as the "attribute" arg # I can now call methods belonging to the class, like this result = b.bank_method(100) # this will show 200 print(result)
Assignment 6 will be due on December 8, 2023 at 11:59pm CST. Above all...have some fun with this and your new skills with object-oriented programming!