- The assumption of this practice is you already have supermarket_practice.py and supermarket_item.py. If you have not, do this one first: https://www.ayclogic.com/python-oop-supermarket-practice/
- In the supermarket_practice.py file add a new method list_all_frozen_items(self). Inside this method loop through every element inside the dictionary and print Frozen item. Frozen item is when supermarket_item.frozen == True. Call this method, so it will print all Frozen item.
- Create a new file game.py. Inside this game.py, create a Game class with the following attribute: name, price, single_player, console.
- Inside this Game class, add a new method get_info() that will return information about this game. Look at Student class in the SchoolApplication on how to do get_info() method.
- Inside this Game class, add a new method multi_player(self). This method will return either True or False boolean. If single_player attribute is True, then this method will return False. If single_player attribute is False, then this method will return True.
- Inside supermarket_system.py, Inside the SupermarketSystem.__init__ method add a new attribute game_dictionary. set this attribute as an empty dictionary.
- Inside supermarket_system.py, Inside the SupermarketSystem class, add a new method initialize_games(self).
- Inside this new initialize_games(self) method, add several games into game_dictionary attribute. The key would be name of the game, the value would be the Game class. Don’t forget to import the Game class on the top of the file:
- Mario, $50, single_player is True, console is “Switch”
- Zelda, $60, single_player is True, console is “Switch”
- Street Fighter, $50, single_player is False, console is “X- Box”
- Mario Party, $40, single_player is False, console is “Switch”
- Inside SupermarketSystem.__init__(self) call this initialize_games() method.
- Change the menu inside SupermarketSystem from
What do you want to purchase:
1. Milk - $5
2. Ice Cream - $4
3. Bread - $6
4. I am done, checkout please
Enter your selection:
- into
What do you want to purchase:
1. Milk - $5
2. Ice Cream - $4
3. Bread - $6
4. Buy Video Game
5. I am done, checkout please
Enter your selection:
- Inside run() method change the code so when user select 5, it will checkout.
- Inside run() method change the code so when user select 4, it will display the following sub menu
Which game consoles you want to see
1. Switch
2. X-Box
3. Play Station
Enter your selection:
- When user select 1, loop through all Games inside game_dictionary and display all games whose console is “Switch”.
- When user select 2, loop through all Games inside game_dictionary and display all games whose console is “X-Box”
- When user select 3, loop through all Games inside game_dictionary and display all games whose console is “Play Station”. If there is no game whose console is “Play Station” then print “No Play Station games available.”