In: Computer Science
This needs to be in Python and each code needs to be separated.
Design a class for a fast food restaurant meals that should have 3 attributes; Meal Type (e.g., Burger, Salad, Taco, Pizza); Meal size (e.g., small, medium, large); Meal Drink (e.g., Coke, Dr. Pepper, Fanta); and 2 methods to set and get the attributes.
Write a program that ask the user to input the meal type, meal size, and meal drinks. This data should be stored as the object's attributes. Use the object's accessor methods to retrieve the meal type, meal size, and meal drinks and display them as the output.
CODE
meals.py
# class Meal
class Meals:
# variables to store type, size and drink of meal
meal_type = ''
meal_size = ''
meal_drink = ''
# setter function to set the values of variable
def setter(self,mtype,msize,mdrink):
self.meal_type = mtype
self.meal_size = msize
self.meal_drink = mdrink
# getter function to get values from the class
def getter(self):
return (self.meal_type, self.meal_size, self.meal_drink)
fastfood.py
# importing meals file into this file
import meals
# reading uwer input
mtype = input("Enter the meal you want: ")
msize = input("Enter the size of meal: ")
mdrink = input("Enter the drink you want: ")
#creating an object of Meals class
obj = meals.Meals()
# giving user input as argument to setter function
obj.setter(mtype,msize,mdrink)
# retrieving the values from class using getter and printing them
print("Meal Type: ",obj.getter()[0])
print("Meal Size: ",obj.getter()[1])
print("Drink: ",obj.getter()[2])
CODE SCREENSHOT
OUTPUT