Question

It's my python homework. Not Java. Design type 1: # Creating an object of the class...

It's my python homework. Not Java.

Design type 1:

# Creating an object of the class "DeAnzaBurger"

theOrder = DeAnzaBurger()

# calling the main method

theOrder.main()

# And the class is like:

class DeAnzaBurger:

# You may need to have a constructor

def __init__(self):
self._orderDict = {}

self._priceBeforeTax = 0

self._priceAfterTax = 0

# you may have the tax rate also as an instance variable. But as I mentioned, you can use your

# own deign.

   ....

# That the class has a main method to run other needed methods. Like:

def main(self):
self.displayMenu()
self.getInput()

self.calculateTheBill()

...

self.printTheBill()

self.saveToFileTheBill()

  

def displayMenu(self):

# display the menu

...

def getInput(self):

# Get the order from the user and fill the "_orderDict" instance variable. - You may return some

# variable from this class. It's depend on your design.

....

  

def calculateTheBill(self):

# Calculate the price before and after tax. - You may pass in or return some variable from this class.

# It's depend on your design.

...

def printTheBill(self):

# Print the bill on the console - You may pass some variable in this class. It's depend

# on your design.

def saveToFileTheBill(self):

# Save the bill in a file - You may pass some variable in this class. It depends

# on your design.

# This method can be merged with the printTheBill together. It depends on your design.

Design type 2:

# Creating an object of the class "DeAnzaBurger"

theOrder = DeAnzaBurger()

# calling the needed method

theOrder.displayMenu()
theOrder.getInput()

theOrderDict = theOrder.getOrderDict()

theOrder.calculateTheBill(theOrderDict )

theOrderBalance = theOrder.getTheBalance()

...

theOrder.printTheBill(theOrderBalance)

theOrder.saveTheBillToFile(theOrderBalance )

# And the class may be the same as the design type 1 class with some changes.

class DeAnzaBurger:

...

...

For design type 2, you may need mutators and accessors:

def setOrderDict(theUpdatedOrderDict):

  _orderDict = theUpdatedOrderDict

def getOrderDict():

return _orderDict

***********************************************************************************************************

  • Use a dictionary as a data structure to send data from a method to another method. Or make it as an instance variable. Then you can fill it and use it everywhere in your class.
    • you may need 2 dictionaries("_" means they are private):

_menuDict = {'De Anza Burger':5.25,'Bacon Cheese':5.75, ... ,'Don Cali Burger':5.95}

which the keys are the food name and the values are the prices.

_orderDict = {'Bacon Cheese':5, ... ,'Don Cali Burger':2}

which the keys are the order (food) name and the values are the quantities of the orders.

(As I mentioned, these all are samples and you can have your own designs and names.)

  • Print the bill on the screen and also in a file.

Use the following naming style for your file - you may use it in the saveToFileTheBill method.

import time # <= This line can be on the top of your code
timeStamp = time.time()
# print(timeStamp) # <= You don't need this line. I just put it here to show you what the output will be.
#1533498418.1082168

import datetime
orderTimeStamp = datetime.datetime.fromtimestamp(timeStamp).strftime('%Y-%m-%d %H-%M-%S')
# print(orderTimeStamp)   # <= You don't need this line. I just put it here to show you what the output will be.
#2018-08-05 12-46-58

# Then concatenate this string with ".txt"

orderTimeStamp = orderTimeStamp + '.txt'

# 2018-08-05 12-46-58.txt

# Now you can use this string as your output file name:

fileHandleToSaveTheBill = open(orderTimeStamp,'w')

  • Use strip() function to strip your inputs.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import collections
from string import capwords


def foodplan(price, stock):
if not str(stock).isdecimal():
raise ValueError("Can only assign a whole number to stock attribute")
return type('FoodPlan', (object,), dict(price=float(price), stock=int(stock)))


def get_choice():
while True:
option = input("What would you like? ")
if option.isdecimal() and 0 <= int(option) - 1 < len(choices):
return list(choices.keys())[int(option) - 1]
elif capwords(option) in choices.keys():
return capwords(option)
else:
print("Invalid item")


def get_quantity(choice):
while True:
quantity = input("How many would you like? ")
if quantity.isdecimal():
if int(quantity) <= choices[choice].stock:
return int(quantity)
else:
print("There is not enough stock!")
else:
print("Illegal quantity")


choices = collections.OrderedDict({
"Big Mac": foodplan(2.50, 50),
"Large Fries": foodplan(0.50, 200),
"Vegetarian Burger": foodplan(1.00, 20),
})


if name == '_main_':

orders = dict(zip(choices.keys(), [0] * len(choices)))

print("Welcome to McDonald's")
ordering = 'y'
while ordering == 'y':
[print("{0}. {1}, £{2}".format(
i + 1, list(choices.keys())[i], list(choices.values())[i].price
)) for i in range(len(choices))]
choice = get_choice()
quantity = get_quantity(choice)
orders[choice] += quantity
choices[choice].stock -= quantity
ordering = input("Do you want to order more items? [y/*] ").lower()
print("\nThank you for ordering!\nYour total cost is: £{0}".format(
sum([orders[choice] * choices[choice].price
for choice in choices.keys()])
))

Add a comment
Know the answer?
Add Answer to:
It's my python homework. Not Java. Design type 1: # Creating an object of the class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of ...

    This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...

  • Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs the missing words in the 4th line are 'To save an attri...

    Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs the missing words in the 4th line are 'To save an attribute, attach it to this self keyword' W11 - Critters Implement the Critter class. Each critter C has attributes species, size, and age The constructor accepts arguments for the attributes above, in the order above. You can expect size and age to be numeric values Each critter C has a can_eat) method,...

  • Now, create a Deck class that consists of 52 cards (each card is an instance of...

    Now, create a Deck class that consists of 52 cards (each card is an instance of class Card) by filling in the template below. Represent the suit of cards as a string: "Spades", "Diamonds", "Hearts", "clubs" and the rank of cards as a single character or integer: 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", class Deck: def init (self): pass # Your code here. def draw (self): Returns the card at the top of the deck, and...

  • Python only please, thanks in advance. Type up the GeometricObject class (code given on the back...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default...

    Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

  • Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name=''...

    Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name='' #declaring attributes in class address='' status='' sales_tax_percentage=0.0 def __init__(self,name,address,status,sales_tax_percentage): #init method to initialize the class attributes self.name=name self.address=address self.status=status self.sales_tax_percentage=sales_tax_percentage def get_name(self): #Getter and setter methods for variables return self.name def set_name(self,name): self.name=name def get_address(self): return self.address def set_address(self,address): self.address=address def set_status(self,status): self.status=status def get_status(self): return self.status def set_sales_tax_percentage(self,sales_tax_percentage): self.sales_tax_percentage=sales_tax_percentage def get_sales_tax_percentage(self): return self.sales_tax_percentage def is_store_open(self): #check store status or availability if self.status=="open": #Return...

  • Type up the GeometricObject class (code given on the back of the paper). Name this file Geometric...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • need help to complete the task: app.py is the Python server-side application. It includes a class...

    need help to complete the task: app.py is the Python server-side application. It includes a class for representing the list of albums. You need to complete the missing parts such that it loads data from the data/albums.txt and data/tracks.txt files. You can decide what internal data structure you want to use for storing the data. It is already implemented that a single instance of the Albums class is used, so that loading from the files happens only once (and not...

  • In Python !!! In this exercise you will continue to work with Classes and will build...

    In Python !!! In this exercise you will continue to work with Classes and will build on the Book class in Lab 13.10; you should copy the code you created there as you will need to extend it in this exercise. You will extend the Book class to accommodate the case where there may be multiple authors for a book. The attribute author should become a list. The constructor will still take a parameter that is a string for author,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT