Question

In: Computer Science

This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1)...

This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)

  • item_description (string) - Set to "none" in default constructor

Implement the following method for the ItemToPurchase class.

  • print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.


Ex. of print_item_description() output:

Bottled Water: Deer Park, 12 oz.

(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps.

  • Parameterized constructor which takes the customer name and date as parameters (2 pts)
  • Attributes
    • customer_name (string) - Initialized in default constructor to "none"
    • current_date (string) - Initialized in default constructor to "January 1, 2016"
    • cart_items (list)
  • Methods
    • add_item()
      • Adds an item to cart_items list. Has parameter ItemToPurchase. Does not return anything.
    • remove_item()
      • Removes item from cart_items list. Has a string (an item's name) parameter. Does not return anything.
      • If item name cannot be found, output this message: Item not found in cart. Nothing removed.
    • modify_item()
      • Modifies an item's quantity. Has parameter ItemToPurchase. Does not return anything.
      • If item can be found (by name) in cart, modify item in cart.
      • If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified.
    • get_num_items_in_cart() (2 pts)
      • Returns quantity of all items in cart. Has no parameters.
    • get_cost_of_cart() (2 pts)
      • Determines and returns the total cost of items in cart. Has no parameters.
    • print_total()
      • Outputs total of objects in cart.
      • If cart is empty, output this message: SHOPPING CART IS EMPTY
    • print_descriptions()
      • Outputs each item's description.

Ex. of print_total() output:

John Doe's Shopping Cart - February 1, 2016
Number of Items: 8

Nike Romaleos 2 @ $189 = $378
Chocolate Chips 5 @ $3 = $15
Powerbeats 2 Headphones 1 @ $128 = $128

Total: $521


Ex. of print_descriptions() output:

John Doe's Shopping Cart - February 1, 2016

Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semi-sweet
Powerbeats 2 Headphones: Bluetooth headphones


(3) In main section of your code, prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart. (1 pt)

Ex.

Enter customer's name:
John Doe
Enter today's date:
February 1, 2016

Customer name: John Doe
Today's date: February 1, 2016


(4) In the main section of your code, implement the print_menu() function. print_menu() has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the function.

If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call print_menu() in the main() function. Continue to execute the menu until the user enters q to Quit. (3 pts)

Ex:

MENU
a - Add item to cart
r - Remove item from cart
c - Change item quantity
i - Output items' descriptions
o - Output shopping cart
q - Quit

Choose an option:


(5) Implement Output shopping cart menu option. (3 pts)

Ex:

OUTPUT SHOPPING CART
John Doe's Shopping Cart - February 1, 2016
Number of Items: 8

Nike Romaleos 2 @ $189 = $378
Chocolate Chips 5 @ $3 = $15
Powerbeats 2 Headphones 1 @ $128 = $128

Total: $521


(6) Implement Output item's description menu option. (2 pts)

Ex.

OUTPUT ITEMS' DESCRIPTIONS
John Doe's Shopping Cart - February 1, 2016

Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semi-sweet
Powerbeats 2 Headphones: Bluetooth headphones


(7) Implement Add item to cart menu option. (3 pts)

Ex:

ADD ITEM TO CART
Enter the item name:
Nike Romaleos
Enter the item description:
Volt color, Weightlifting shoes
Enter the item price:
189
Enter the item quantity:
2


(8) Implement remove item menu option. (4 pts)

Ex:

REMOVE ITEM FROM CART
Enter name of item to remove:
Chocolate Chips


(9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object before using ModifyItem() method. (5 pts)

Ex:

CHANGE ITEM QUANTITY
Enter the item name:
Nike Romaleos
Enter the new quantity:
3.

Type in Python please.

Solutions

Expert Solution

#Online Shopping Cart -python 3

class Items To Purchase:

def __init__(self, name = "none", price = 0, quantity 0):

self.name = name

self.price = price

self.quantity = quantity

def print_item_cost(self):

print( self.name + " " +str(self .price) + " @ $" + str(self.price) " = $ " + str(self.price *self.quantity))

def main():

print("Item 1" + "\n")

item1 = ItemToPurchase()

item1.name = input("Enter name: + "\n")

item1.price = int(input("Enter the item price:" + "\n"))

item1.quantity = int(input("Enter the item quantity:" + "\n"))

print("Item 2" + "\n")

item2 = ItemToPurchase()

item2.name = input("Enter the item name:" + "\n")

item2.price = int(input("Enter the = item price:" + "\n"))

item2.quantity = int(input("Enter the item quantity:" + "\n"))

print("TOTAL COST" + "\n")

item1.print_item_cost() item2.print_item_cost()

print('\n'+'Total: $' + str(((item1.price *item1.quantity) + (item2 .price * item2.quantity))))

def remove_from_cart(request, item):

cart = get_shopping_cart(request)

cart.remove_item(int(item))

update_shopping_cart(request, cart)

cart = get_shopping_cart(request)

ctx = {'cart': cart}

def update_shopping_cart(request, cart):

request.session['cart'] = cart

main()


Related Solutions

This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1)...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. (2 pts) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz. (2) Build the ShoppingCart class with the following data attributes and related methods....
C++.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1)...
C++.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() - Outputs the item name and description Private data members string itemDescription -...
7.7 Ch 7 Program: Online shopping cart (continued) (C) This program extends the earlier "Online shopping...
7.7 Ch 7 Program: Online shopping cart (continued) (C) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase struct to contain a new data member. (2 pt) char itemDescription[ ] - set to "none" in MakeItemBlank() Implement the following related functions for the ItemToPurchase struct. PrintItemDescription() Has an ItemToPurchase parameter. Ex. of PrintItemDescription() output: Bottled Water: Deer Park, 12 oz. (2) Create three new files: ShoppingCart.h - struct definition and...
IN C++ 7.22 LAB*: Program: Online shopping cart (Part 2) This program extends the earlier "Online...
IN C++ 7.22 LAB*: Program: Online shopping cart (Part 2) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() - Outputs the...
In python 3 please: This program extends the earlier "Online shopping cart" program. (Start working from...
In python 3 please: This program extends the earlier "Online shopping cart" program. (Start working from your Program 7). (1) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps.(3 pt) ● Parameterized constructor which takes the customer name and date as parameters ● Attributes ○ customer_name (string) ○ current_date (string) ○ cart_items (list) ● Methods ○ add_item() ■ Adds an item to...
This week you will write a program that mimics an online shopping cart . You will...
This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers for quantities -...
Python This week you will write a program in Python that mimics an online shopping cart...
Python This week you will write a program in Python that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
Python This week you will write a program in Pyhton that mimics an online shopping cart...
Python This week you will write a program in Pyhton that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
9.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same...
9.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input. This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Private fields string itemDescription -...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a class named GroceryItem. This class should contain: - an __init__ method that initializes the item’s name and price - a get_name method that returns the item’s name - a get_price method that returns the item’s price - a __str__ method that returns a string representation of that GroceryItem - an unimplemented method is_perishable Save this class in GroceryItem.py. 2. Create a subclass Perishable that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT