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...
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...
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...
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()...
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...
write a program in java that contain a class for botique . data member include code...
write a program in java that contain a class for botique . data member include code , color , size , quantity . your class should contains all accessor and mutator methods , non paraqmetric constructor , parametric constructor , input andvidsplay method
Modify the supplied payroll system to include a private instance variable called joinDate in class Employee...
Modify the supplied payroll system to include a private instance variable called joinDate in class Employee to represent when they joined the company. Use the Joda-Time library class LocalDate as the type for this variable. See http://www.joda.org/joda-time/index.html for details end examples of how to use this library. You may also have to download the Joda-Time library (JAR File) and include this in your CLASSPATH or IDE Project Libraries. Use a static variable in the Employee class to help automatically assign...
Create a new project ‘Clocky’ - Create a ‘ClockAlarm’ class Include 1 member – a List...
Create a new project ‘Clocky’ - Create a ‘ClockAlarm’ class Include 1 member – a List alarmTimes Create an accessor and mutator Create a method addAlarmTime which adds an alarm time to your list Create a method deleteAlarmTIme which removes an alarm time from your list Create a method – displayAlarmTimes which prints all alarm times in the list - Create a ‘Clock’ class - include at least 2 members - one member of Clock class needs to be private...
To convert from a given quantity of one reactant or product to the quantity of another...
To convert from a given quantity of one reactant or product to the quantity of another reactant or product: First, convert the given quantity to moles. Use molar masses to convert masses to moles, and use Avogadro's number (6.02×1023 particles per mole) to convert number of particles to moles. Next, convert moles of the given reactant or product to moles of the desired reactant or product using the coefficients of the balanced chemical equation. For example, in the chemical equation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT