Question: Write a program that simulates a soda dispenser using a stack data structure. Create a class named SodaDispenser with methods to manage the dispenser. Implement
Write a program that simulates a soda dispenser using a stack data structure. Create a class named SodaDispenser with methods to manage the dispenser. Implement the following methods: addsodaself soda to add a soda represented as a string to the top of the dispenser, dispensesodaself to remove and return the soda from the top of the dispenser, handling the case where the dispenser is empty by raising an exception or returning a special value, isemptyself to return True if the dispenser is empty and False otherwise, and peeksodaself to return the soda at the top of the dispenser without removing it also handling the empty dispenser scenario appropriately. Ensure your program includes test cases demonstrating the functionality of these methods. Submit your implementation in Blackboard as a file named SodaDispenser followed by your name and ID using the appropriate file extension for the language you choose. Your submission will be evaluated on the correctness of the methods, handling of edge cases, code readability, and proper commenting.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
