Need help solving this qestion related to object and item classes involving arrays in PYTHON.
Classes and Object - Inventory Item as Object
In this assignment the idea is to use an Item class to capture what you need for recording and displaying the details of an order from an online store like Amazon. This is a Class and Object assignment.
For the assignment you must define and implement the Item class so that the code shown immediately below can produce the result shown below that. You will need to define the four private variables of the Item class for the price, weightInOunces , description, and quantity.
You are to include a constructor (__init__), that takes three input parameters for the price, weightInOunces, and description, but not quantity which should be set to a default value of 1
You will also need to create the remaining methods that are used in the code below the gets and sets. The contents of the main function and the output are shown below. Copy, and do not change, the code below. Pay close attention to the values in the output. If you do not match the details correctly, some of your values will not be the same as those shown. (Hint: There’s a reason that the getOrderPrice() method is not called getPrice() and in the example it affects the order for glasses.) Name your main file youOrderReceipt.py, e.g. StudentNameOrderReceipt.py.
Part B:
Create a second main file youOrderReceiptArray.py e.g. AjoyOrderReceiptArray.
Using an list of item objects, instead of item1, item2, etc. Put item1 item2, item3 and item4 in the list. For each item in the list call __str__() and Use the list and the for loop to find the dTotalPrice and iTotalWeight as in part A.
Turn in your zipped package folder with all the three .py source files(Item.py and the two main files). Having correct formatting will now be part of the grade.
def main():
dTotalPrice = 0.0
iTotalWeight = 0
# Put the 4 items being ordered in item1 through item 4
item1 = Item.Item(24.99, 14, "Wireless Mouse")
item2 = Item.Item(22.49, 27, "USB Keyboard")
item3 = Item.Item(24.99, 12, "HDMI Cable")
item4 = Item.Item(7.99, 7, "Reading Glasses")
item4.set_quantity(2);
# Show the details of the order using show()
print("Here are your shopping cart contents.")
print(item1);
print(item2);
print(item3);
print(item4);
# Compute the total price and total weight in this section
dTotalPrice += item1.getOrderPrice()
dTotalPrice += item2.getOrderPrice()
dTotalPrice += item3.getOrderPrice()
dTotalPrice += item4.getOrderPrice()
iTotalWeight += item1.getOrderWeightInOunces()
iTotalWeight += item2.getOrderWeightInOunces()
iTotalWeight += item3.getOrderWeightInOunces()
iTotalWeight += item4.getOrderWeightInOunces()
# Here we show the order details
print("The price of your order is $" + str(dTotalPrice));
print("The shipping weight is", (int)(iTotalWeight / 16),
"pounds", iTotalWeight % 16 , "ounces");
main()
The method __str__() should print out as shown below for each item.
$24.99 each for 1 Wireless Mouse.
$22.49 each for 1 USB Keyboard.
$24.99 each for 1 HDMI Cable.
$7.99 each for 2 Reading Glasses.
to achieve above tasks we can follow below steps :
the below code will explain better :


the text code :
class Item:
def __init__(self , price , weightounces ,
description):
self.__price = price
#private members satrt with __
self.__weightounces =
weightounces
self.__description =
description
self.__quantity =
1
def set_price(self
,price): #setter functions for 4 memebers
self.__price =
price
def set_weightounces(self ,weight):
self.__weightounces =
weight
def set_description(self, des):
self.__description =
des
def set_quantity(self ,quantity):
self.__quantity =
quantity
def
getOrderPrice(self): #getter functions for ll
variables.
return
self.__price
def getOrderWeightInOunces(self):
return
self.__weightounces
def getDescription(self):
return
self.__description
def getQuantity(self):
return
self.__quantity
def __str__(self):
#__str__ modifier function to return a string whenever the print
fucntion will call th eobject itself.
return f'${self.__price}
each for {self.__quantity} {self.__description}'
def main():
dTotalPrice = 0.0
iTotalWeight = 0
# Put the 4 items being ordered in item1 through item 4
item1 = Item(24.99, 14, "Wireless Mouse")
item2 = Item(22.49, 27, "USB Keyboard")
item3 = Item(24.99, 12, "HDMI Cable")
item4 = Item(7.99, 7, "Reading Glasses")
item4.set_quantity(2);
# Show the details of the order using show()
print("Here are your shopping cart contents.")
print(item1);
print(item2);
print(item3);
print(item4);
# Compute the total price and total weight in
this section
dTotalPrice +=
item1.getOrderPrice()
dTotalPrice += item2.getOrderPrice()
dTotalPrice += item3.getOrderPrice()
dTotalPrice += item4.getOrderPrice()
iTotalWeight += item1.getOrderWeightInOunces()
iTotalWeight += item2.getOrderWeightInOunces()
iTotalWeight += item3.getOrderWeightInOunces()
iTotalWeight +=
item4.getOrderWeightInOunces()
# Here we show the order details
print("The price of your order is $" +
str(dTotalPrice));
print("The shipping weight is", (int)(iTotalWeight / 16),
"pounds", iTotalWeight % 16 , "ounces");
print('***********************')
print("List implementation ")
item_list = [item1 , item2 , item3 ,
item4] #create a list of items.
for x in item_list: #iteratively print all the 4
objects
print(x)
main()
Need help solving this qestion related to object and item classes involving arrays in PYTHON. Classes...
PYTHON 3 Object Oriented Programming
***a9q3.py file below***
class GradeItem(object):
# A Grade Item is anything a course uses in a grading scheme,
# like a test or an assignment. It has a score, which is assessed by
# an instructor, and a maximum value, set by the instructor, and a weight,
# which defines how much the item counts towards a final grade.
def __init__(self, weight, scored=None, out_of=None):
"""
Purpose:
Initialize the GradeItem object.
Preconditions:
:param weight: the weight...
C++ program, item.cpp implementation.
Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...
Problem Description to implement a Java application, called ShoppingApplication, that can be used in a retail store. You are asked to implement three classes: Item, Invoice, and InvoiceDriver. Each of these classes is described below. Item class The Item class represents of an item that is being sold in the retail store (e.g., book or pencil) where an item is identified by three instance variables: name (of type Sring), weight (of type double), price (of type double), and currentDiscount (of...
Need help finishing this code # Description : The Pet class contains fields for name, pet # type,and age. The age field is the age now # or age of pet when it passed away. (These # are all dogs I have had.) There is a static or # class variable called number_pets that # tracks how many instances have been created. # The constructor will fill all fields and add # one to the number_pets variable. # The special...
YOU NEED TO MODIFY THE PROJECT INCLUDED AT THE END AND USE THE INCLUDED DRIVER TO TEST YOUR CODE TO MAKE SURE IT WORK AS EXPECTED. Thanks USING PYTHON, complete the template below such that you will provide code to solve the following problem: Please write and/or extend the project5 attached at the end. You will have to do the following for this assignment: Create and complete the methods of the PriceException class. Create the processFile function. Modify the main...
For Python-3 I need help with First creating a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots. Write a python program that 1. Puts this as the first line... import os 2. Creates an empty list 3. Defines main() function that performs the tasks listed below when called. 4. Put these two lines at the top of the main function... if os.path.exists("costlist.txt"): os.remove("costlist.txt") Note: This removes the "costlist.txt" file, if it exists. 5....
Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...
PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots ... and have it be in the same directory as the Python program you are coding for this assignment. IMPORTANT: Your program should work with any size file. It should work with 100 items listed or with no items in the file! Write a Python program that ... 1....
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...