In this task, we will build a system for buying and selling ice-cream.
- Fork this repo.
- Clone it in your Development/Foundations directory.
- Write the code in
main.py
. - Push your code when you're done.
This class Wallet
keeps track of money. It has the following properties and methods:
money
: The amount of money in the wallet. Defaults to 0.credit(amount)
: this method adds theamount
to themoney
property, then prints the new value ofmoney
in a nice message.debit(amount)
:this method subtracts theamount
from themoney
property, then prints the new value ofmoney
in a nice message.
This class Person
defines a person with a name, location and wallet. It has the following properties and methods:
name
: name of said personlocation
: a number that represents the person's place (Any number, don't overthink it).wallet
: aWallet
instance. Create a Wallet instance and pass it as a property to this class.moveTo(point)
: updates thelocation
property topoint
, then prints the new value oflocation
in a nice message.
This class Vendor
is a subclass of Person
. Yes, you need to inherit! It has the following properties and methods:
range
: the maximum distance this vendor can travel - initially 5price
: the cost of a single ice cream - initially 1sellTo(customer, number_of_icecreams):
sells a specific number of ice creams to the customer by doing the following:- Moves to the customer's location
- Transfers money from the customer's wallet to the vendor's wallet
- Prints a nice message saying how many icecreams were sold
This class Customer
is a subclass of Person
. Yes, you need to inherit! It has the following properties and methods:
_is_in_range(vendor)
:- Checks if the customer is in range of vendor.
- To check the range, you need to find the distance between the vendor and customer by subtracting their locations from each other (Convert it to a positive number).
- If the distance is less than or equal to the vendor's range, then this customer is within range.
- Prints a message saying that the customer is in range or not
_have_enough_money(vendor, number_of_icecreams):
- Checks if the customer has enough money to buy a specific number of ice creams from vendor.
- Prints a message saying if the customer has enough money or not.
request_icecream(vendor, number_of_icecreams):
- If the customer is in the vendor's range and has enough money for ice cream, a request is sent to the vendor.
- Print a message saying that a request has been made.