Question

In: Computer Science

Instructions Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include...

Instructions

Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include a getter and setter, using decorators, and modify the appropriate constructor to also accept a quantity parameter.

Then modify the inventory.py file from the practice exercise to include quantity values in the constructor calls with a quantity of 100 for product1 (hammers) and 3000 for product2 (nails). Add print statements to display the quantity values as shown in the Expected Output included below.

Submission

Attach and submit your modified product.py and inventory.py files to this assignment.

Expected Output (new output shown in red, yours does not have to be red).

PRODUCT 1:
Name:                 Stanley 13 Ounce Wood Hammer
Price:                11.25
Discount percent:     62%
Discount amount:      6.97
Discount price:       4.28
Quantity:             100 

PRODUCT 2:
Name:                 National Hardware 3/4" Wire Nails
Price:                5.06
Discount percent:     0%
Discount amount:      0.00
Discount price:       5.06
Quantity:             3000

This assignment requires a file upload submission (Links to an external site.). After you have reviewed the assignment instructions and rubric, as applicable, complete your submission by selecting the Submit Assignment button next to the assignment title.

Solutions

Expert Solution

product class

class product(object):#main class you can inherit it from object if you wish else its work fine.
    Name='' #declraing all the variable of product
    Price=0
    Discount_percent=0
    Discount_amount=0
    Discount_price=0
    Quantity=0
  
    def __init__(self,a,b,c,d): # constructor with name, price,discount amount and quantity
        self.Name=a #asign respective value
        self.Price=b
        self.Discount_percent=c
        self.Discount_amount=b*(c/100)# asign value after calculating discount price
        self.Discount_price=b-b*(c/100)
        self.Quantity=d
    def print_product(self):# this function help to print detail o product
        # you can print all variable of this class by self.variablename but this will help you lot and give same output with 1 line
        print(self.__dict__)# __dict__ is called magic method in python which print all the variable of the class
      
    @property # getter method for quantity @property is called decorator for setter method
    def quantity(self):
        return self.Quantity
  
    @quantity.setter # you have to asign decorator name with name of method asign for getter method and then word setter
    def quantity(self, a):
        self.Quantity = a
# creating object of product
product1=product('Stanley 13 Ounce Wood Hammer',11.25,62,100)
product1.print_product()#printing all values of product one
print('quantity is :',product1.Quantity)# calling getter method it will allow us to access quantity variable without function
#asign new quantity
product1.Quantity=200
print('after setting quantity 200 :',product1.Quantity)

output:--

2nd class

code:--

class inventory(product):
    def __init__(self,obj,quantity):# constructor for inventory.it will accept object and quantity
        obj.Quantity=quantity# asign quantity using inventory object
i1=inventory(product1,100) # creating object for testing
product1.print_product()# asign again 100 quantity to product 1

output:-

NOTE: --

i defind both class on your requirment given but in question i don't know what those class contain earliar so i make it as best.if you have any question let us know.


Related Solutions

Exercise 1 Modify the List class of Figure 21.3 in the textbook to include a method...
Exercise 1 Modify the List class of Figure 21.3 in the textbook to include a method that recursively searches a linked-list for a specified value. Ensure that the name of your method includes your last name. The method must return a reference to the value if it is found; otherwise, it must return null. Use your method in a test program that creates a list of integers. The program must prompt the user for a value to locate in the...
Exercise 1 Modify the List<T> class of Figure 21.3 in the textbook to include a method...
Exercise 1 Modify the List<T> class of Figure 21.3 in the textbook to include a method that recursively searches a linked-list for a specified value. Ensure that the name of your method includes your last name. The method must return a reference to the value if it is found; otherwise, it must return null. Use your method in a test program that creates a list of integers. The program must prompt the user for a value to locate in the...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question) a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the vegetable can be used in...
JAVA- Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The...
JAVA- Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. The class should use recursion to implement the sort and reverse operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods. LinkedList1: class...
Instructions Write the definitions of the member functions of the class integerManipulation not given in Example...
Instructions Write the definitions of the member functions of the class integerManipulation not given in Example 10-11. Also, add the following operations to this class: Split the number into blocks of n-digit numbers starting from right to left and find the sum of these n-digit numbers. (Note that the last block may not have n digits. If needed add additional instance variables.) Determine the number of zeroes. Determine the number of even digits. Determine the number of odd digits Also,...
Modify StudentLinkedList class by adding the following methods: printStudentList: print by calling and printing “toString” of...
Modify StudentLinkedList class by adding the following methods: printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.  sortListByID(): sort the linkedlist according to students IDs.  findMarksAverage(): find the average of all marks for all students in the list.  findMinMark(int markIndex): find the student with the minimum...
Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and...
Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.  sortListByID(): sort the linkedlist according to students IDs.  findMarksAverage(): find the average of all marks for all students in the list.  findMinMark(int markIndex): find the student...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort()...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. Do not use recursion to implement either of these operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods....
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should...
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should include the characters’s name, gender, class* and race (can be human, elf or dwarf), and additional integer attributes of Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma. Your class should have a constructor that receives this data. For each attribute, provide setters and getters. The class should include methods that calculate and return the user’s total attributes (sums 6 attributes). Write a Java application that prompts...
C++ Modify the class unorderedList to include a recursive forward print and a recursive reverse print...
C++ Modify the class unorderedList to include a recursive forward print and a recursive reverse print Make your unorderedList a list of characters instead of integers Insert ten characters into the list and print it out both ways #include <iostream> #include <string> #include <cstdlib> using namespace std; struct node { int info; node* next; }; class unorderedList { private: int length; node* listPtr; public: unorderedList() {length = 0; listPtr = NULL;} void makeEmpty(); void insertItem(int item); void printList(); bool isFull()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT