Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the Zelle graphics.py library, Python code covered in this course and data s

ID: 3707648 • Letter: U

Question

Use the Zelle graphics.py library, Python code covered in this course and data structures covered in this course to solve the following problem: "GO Burger!" is a new 'burger-to-go' establishment who requires an app for customers to place their orders. The establishment only accepts online orders and pick-up...there is no sit-down service available, although there is a beverage vending machine outside the building. Go Burger! sells 1/2 pound quality meat burgers on homemade freshly baked buns at reasonable prices (only $4.50 each!). The application interface should ask the customer for their first name, how many burgers they want to order, and if those burgers come with cheese (at a nominal surcharge of 35 cents per burger). The app should provide the customer with the choice of selecting any of six toppings: lettuce, onions, pickles, mustard, catchup and mayo (these are to no cost to the customer). The app should also provide an area for the customer to add any special instructions in their order (for example the customer may only eat well-done beef). The app should display the total of the order including a 8% sales tax added to the order after the customer selects the "Place Order" button. After ordering ( after the customer selects the "Place Order" button ), the interface should display a message to the customer using their first name and telling them that their order will be ready for pickup in 15 minutes. Use coordinate transformation (the setCoords method) in your program to divide your window for easier placement of objects.

Explanation / Answer

CODING:

Graphics classes start here
  
class GraphWin(tk.Canvas):

"""A GraphWin is a toplevel window for displaying graphics."""

def _init_(self, title="Graphics Window",
width=200, height=200, autoflush=True):
assert type(title) == type(""), "Title must be a string"
master = tk.Toplevel(_root)
master.protocol("WM_DELETE_WINDOW", self.close)
tk.Canvas._init_(self, master, width=width, height=height,
highlightthickness=0, bd=0)
self.master.title(title)
self.pack()
master.resizable(0,0)
self.foreground = "black"
self.items = []
self.mouseX = None
self.mouseY = None
self.bind("<Button-1>", self._onClick)
self.bind_all("<Key>", self._onKey)
self.height = int(height)
self.width = int(width)
self.autoflush = autoflush
self._mouseCallback = None
self.trans = None
self.closed = False
master.lift()
self.lastKey = ""
if autoflush: _root.update()

def _repr_(self):
if self.isClosed():
return "<Closed GraphWin>"
else:
return "GraphWin('{}', {}, {})".format(self.master.title(),
self.getWidth(),
self.getHeight())

def _str_(self):
return repr(self)

def __checkOpen(self):
if self.closed:
raise GraphicsError("window is closed")

def _onKey(self, evnt):
self.lastKey = evnt.keysym


def setBackground(self, color):
"""Set background color of the window"""
self.__checkOpen()
self.config(bg=color)
self.__autoflush()
  
def setCoords(self, x1, y1, x2, y2):
"""Set coordinates of window to run from (x1,y1) in the
lower-left corner to (x2,y2) in the upper-right corner."""
self.trans = Transform(self.width, self.height, x1, y1, x2, y2)
self.redraw()

def close(self):
"""Close the window"""

if self.closed: return
self.closed = True
self.master.destroy()
self.__autoflush()


def isClosed(self):
return self.closed


def isOpen(self):
return not self.closed


def __autoflush(self):
if self.autoflush:
_root.update()

  
def plot(self, x, y, color="black"):
"""Set pixel (x,y) to the given color"""
self.__checkOpen()
xs,ys = self.toScreen(x,y)
self.create_line(xs,ys,xs+1,ys, fill=color)
self.__autoflush()
  
def plotPixel(self, x, y, color="black"):
"""Set pixel raw (independent of window coordinates) pixel
(x,y) to color"""
self.__checkOpen()
self.create_line(x,y,x+1,y, fill=color)
self.__autoflush()
  
def flush(self):
"""Update drawing to the window"""
self.__checkOpen()
self.update_idletasks()
  
def getMouse(self):
"""Wait for mouse click and return Point object representing
the click"""
self.update() # flush any prior clicks
self.mouseX = None
self.mouseY = None
while self.mouseX == None or self.mouseY == None:
self.update()
if self.isClosed(): raise GraphicsError("getMouse in closed window")
time.sleep(.1) # give up thread
x,y = self.toWorld(self.mouseX, self.mouseY)
self.mouseX = None
self.mouseY = None
return Point(x,y)

def checkMouse(self):
"""Return last mouse click or None if mouse has
not been clicked since last call"""
if self.isClosed():
raise GraphicsError("checkMouse in closed window")
self.update()
if self.mouseX != None and self.mouseY != None:
x,y = self.toWorld(self.mouseX, self.mouseY)
self.mouseX = None
self.mouseY = None
return Point(x,y)
else:
return None

def getKey(self):
"""Wait for user to press a key and return it as a string."""
self.lastKey = ""
while self.lastKey == "":
self.update()
if self.isClosed(): raise GraphicsError("getKey in closed window")
time.sleep(.1) # give up thread

key = self.lastKey
self.lastKey = ""
return key

def checkKey(self):
"""Return last key pressed or None if no key pressed since last call"""
if self.isClosed():
raise GraphicsError("checkKey in closed window")
self.update()
key = self.lastKey
self.lastKey = ""
return key
  
def getHeight(self):
"""Return the height of the window"""
return self.height
  
def getWidth(self):
"""Return the width of the window"""
return self.width
  
def toScreen(self, x, y):
trans = self.trans
if trans:
return self.trans.screen(x,y)
else:
return x,y
  
def toWorld(self, x, y):
trans = self.trans
if trans:
return self.trans.world(x,y)
else:
return x,y
  
def setMouseHandler(self, func):
self._mouseCallback = func
  
def _onClick(self, e):
self.mouseX = e.x
self.mouseY = e.y
if self._mouseCallback:
self._mouseCallback(Point(e.x, e.y))

def addItem(self, item):
self.items.append(item)

def delItem(self, item):
self.items.remove(item)

def redraw(self):
for item in self.items[:]:
item.undraw()
item.draw(self)
self.update()
  
  
class Transform:

"""Internal class for 2-D coordinate transformations"""
  
def _init_(self, w, h, xlow, ylow, xhigh, yhigh):
# w, h are width and height of window
# (xlow,ylow) coordinates of lower-left [raw (0,h-1)]
# (xhigh,yhigh) coordinates of upper-right [raw (w-1,0)]
xspan = (xhigh-xlow)
yspan = (yhigh-ylow)
self.xbase = xlow
self.ybase = yhigh
self.xscale = xspan/float(w-1)
self.yscale = yspan/float(h-1)
  
def screen(self,x,y):
# Returns x,y in screen (actually window) coordinates
xs = (x-self.xbase) / self.xscale
ys = (self.ybase-y) / self.yscale
return int(xs+0.5),int(ys+0.5)
  
def world(self,xs,ys):
# Returns xs,ys in world coordinates
x = xs*self.xscale + self.xbase
y = self.ybase - ys*self.yscale
return x,y


# Default values for various item configuration options. Only a subset of
# keys may be present in the configuration dictionary for a given item
DEFAULT_CONFIG = {"fill":"",
"outline":"black",
"width":"1",
"arrow":"none",
"text":"",
"justify":"center",
"font": ("helvetica", 12, "normal")}

class GraphicsObject:

"""Generic base class for all of the drawable objects"""
# A subclass of GraphicsObject should override _draw and
# and _move methods.
  
def _init_(self, options):
# options is a list of strings indicating which options are
# legal for this object.
  
# When an object is drawn, canvas is set to the GraphWin(canvas)
# object where it is drawn and id is the TK identifier of the
# drawn shape.
self.canvas = None
self.id = None

# config is the dictionary of configuration options for the widget.
config = {}
for option in options:
config[option] = DEFAULT_CONFIG[option]
self.config = config
  
def setFill(self, color):
"""Set interior color to color"""
self._reconfig("fill", color)
  
def setOutline(self, color):
"""Set outline color to color"""
self._reconfig("outline", color)
  
def setWidth(self, width):
"""Set line weight to width"""
self._reconfig("width", width)