Question

Write a class called Hamburger in python The Hamburger class should have the following fields: weight...

Write a class called Hamburger in python

The Hamburger class should have the following fields:

  1. weight – an int storing the weight of the hamburger patty in ounces
  2. doneness – a String which stores how well the burger is cooked i.e., rare, medium, well done, etc.
  3. cheese – a boolean indicating whether the burger has cheese or not
  4. toppings – a list of Strings storing the toppings on the burger i.e., lettuce, tomato, mayonnaise, etc.

The Hamburger class should have the following methods:

  1. a constructor
  2. getter and setter methods for each of the fields
  3. a bite method – the bite methods should reduce the weight of the burger by 1 ounce each time it’s called until the weight is 0.
  4. __str__ method

In the same file, write a main function to test the functionality of the Hamburger class.

Homework Answers

Answer #1
class Hamburger:
    def __init__(self, weight, doneness, cheese, toppings):
        self.weight = weight
        self.doneness = doneness
        self.cheese = cheese
        self.toppings = toppings

    def set_weight(self, weight):
        self.weight = weight

    def set_doneness(self, doneness):
        self.doneness = doneness

    def set_cheese(self, cheese):
        self.cheese = cheese

    def set_toppings(self, toppings):
        self.toppings = toppings

    def get_weight(self):
        return self.weight

    def get_doneness(self):
        return self.doneness

    def get_cheese(self):
        return self.cheese

    def get_toppings(self):
        return self.toppings

    def bite(self):
        if self.weight >= 1:
            self.weight -= 1

    def __str__(self):
        return "weight: {}, doneness: {}, cheese: {}, toppings: {}".format(self.weight, self.doneness, self.cheese,
                                                                           self.toppings)


def main():
    h = Hamburger(10, 'medium', True, ['lettuce', 'mayo'])
    print(h)


main()

Know the answer?
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
Similar Questions
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
java Create a program that defines a class called circle. Circle should have a member variable...
java Create a program that defines a class called circle. Circle should have a member variable called radius that is used to store the radius of the circle. Circle should also have a member method called calcArea that calculates the area of the circle using the formula area = pi*r^2. Area should NOT be stored in a member variable of circle to avoid stale data. Use the value 3.14 for PI. For now, make radius public and access it directly...
Write a class named Car that has the following fields: • yearModel: The yearModel field is...
Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values should...
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following...
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following 4 fields: int x (x-coordinate for its top left corner) int y (y coordinate for its top left corner) double height (height of the rectangle) double width (width of the rectangle) Your rectangle objects should have the following methods: public Rectangle(int newx, int newy, int newwidth, int newheight) Constructor that initializes the x-coordinate, y-coordinate for the top left corner and its width and height....
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...