Question

In: Computer Science

#Create a class called FrapOrder. FrapOrder should #have two attributes (instance variables): size and #extra_shots. Make...

#Create a class called FrapOrder. FrapOrder should
#have two attributes (instance variables): size and
#extra_shots. Make sure the variable names match those
#words. size will be a character, either "S", "M", or "L".
#extra_shots will be an integer.
#
#FrapOrder should have a constructor with two required
#parameters, one for each of those attributes (size and
#extra_shots, in that order).
#
#FrapOrder should also have a method called get_total.
#get_total should calculate the total cost of the order.
#If size is "S", the base cost is 2.50. If the size is "M",
#the base cost is 3.50. If the size is "L", the base cost is
#4.50. Then, each extra shot costs $0.35.
#
#For example, if size is "M" and extra_shots is 2, then
#get_total would return 4.2: 3.50 + 0.70 = 4.20 (and Python
#drops trailing 0s).
#
#total should NOT be an attribute of the class; instead,
#total should be calculated and returned live when the method
#get_total is called.
#
#The get_total method should have NO parameters besides self.
#Instead, it should calculate the total based on the current
#values for the size and extra_shots attributes.


#Write your class here!

#The code below will test your function. If it works, it
#should print "M" (without the quotes), 2, and 4.2 in that
#order.
test_order = FrapOrder("M", 2)
print(test_order.size)
print(test_order.extra_shots)
print(test_order.get_total())

Solutions

Expert Solution

# Create a class called FrapOrder. FrapOrder should
# have two attributes (instance variables): size and
# extra_shots. Make sure the variable names match those
# words. size will be a character, either "S", "M", or "L".
# extra_shots will be an integer.
#
# FrapOrder should have a constructor with two required
# parameters, one for each of those attributes (size and
# extra_shots, in that order).
#
# FrapOrder should also have a method called get_total.
# get_total should calculate the total cost of the order.
# If size is "S", the base cost is 2.50. If the size is "M",
# the base cost is 3.50. If the size is "L", the base cost is
# 4.50. Then, each extra shot costs $0.35.
#
# For example, if size is "M" and extra_shots is 2, then
# get_total would return 4.2: 3.50 + 0.70 = 4.20 (and Python
# drops trailing 0s).
#
# total should NOT be an attribute of the class; instead,
# total should be calculated and returned live when the method
# get_total is called.
#
# The get_total method should have NO parameters besides self.
# Instead, it should calculate the total based on the current
# values for the size and extra_shots attributes.


class FrapOrder:
    def __init__(self, size, extra_shots):
        self.size = size
        self.extra_shots = extra_shots

    def get_total(self):
        cost = self.extra_shots * 0.35
        if self.size == 'S':
            cost += 2.50
        elif self.size == 'M':
            cost += 3.50
        elif self.size == 'L':
            cost += 4.50
        return cost


# The code below will test your function. If it works, it
# should print "M" (without the quotes), 2, and 4.2 in that
# order.
test_order = FrapOrder("M", 2)
print(test_order.size)
print(test_order.extra_shots)
print(test_order.get_total())



Related Solutions

This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length and #width. Make sure the variable names match those words. #Both will be floats. # #Rectangle should have a constructor with two required #parameters, one for each of those attributes (length and #width, in that order). # #Rectangle should also have a method called #find_perimeter. find_perimeter should calculate the #perimeter of the rectangle based on the current values for #length and width. # #perimeter...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # #...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # # - meat # - to_go # - rice # - beans # - extra_meat (default: False) # - guacamole (default: False) # - cheese (default: False) # - pico (default: False) # - corn (default: False) # #The constructor should let any of these attributes be #changed when the object is instantiated. The attributes #with a default value should be optional. Both positional #and...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.”
Programming Problem 2 - Cycle[A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list.[B] Edit your class Cycle by...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
(a) Create a Card class that represents a playing card. It should have an int instance...
(a) Create a Card class that represents a playing card. It should have an int instance variable named rank and a char variable named suit. Include the following methods: A constructor with two arguments for initializing the two instance variables. A copy constructor. A method equals — with one argument — which compares the calling object with another Card and returns true if and only if the corresponding ranks and suits are equal. Make sure your method will not generate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT