Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 1 In a file called prescriptions.py, (available for download from the PROBLEM SETS module), complete the Python program given below to define a class
Question 1 In a file called prescriptions.py, (available for download from the PROBLEM SETS module), complete the Python program given below to define a class called Prescription to generate objects with the following attributes/instance variables: pName: name of the person for whom the prescription is written mcp: person's medical care plan number drugName: name of the prescribed medicine noOfRefillsLeft: number of times the prescribed medicine can currently be refilled dName: name of the doctor who wrote the prescription dUnitCost: the unit cost of the drug noOfUnits: the number of units ordered for the drug, per fill/refill O NOTE: To implement encapsulation, all of the instance variables/fields should considered private. 0 Also include the following class variables: NoofPrescriptions - maintains the total number of prescription objects created. TotalCost - the total cost of all prescription objects for one fill/refill of each (including dispensing fee see below). The class definition should also include the following methods: a constructor/initializer method Ows se activate a constructor/initializer method accessor methods to get the name of the person number of refills left mutator method to change the number of refills if the user decides to refill their prescription; note that there must be a message printed if there are no refills left, otherwise the number of refills left should decrease and the new number of refills left should be printed, appropriately labelled a method to compute the cost for the prescription including a dispensing fee; assume that the dispensing fee is 15% of the computed cost of the drug a special method, str (), that returns formatted information for the object, including the person's name, MCP number, doctor's name, name of the drug, number of refills and the amount to be paid for one fill/refill (including dispensing fee) Once the class of objects is designed it must be tested. Test the defined class Prescriptions by performing the following operations in a main function: Create two prescription objects using the following two sets of data (name of the patient, MCP, name of the drug, number of units of the drug prescribed, number of refills, doctor's name, unit cost of the drug): "Rolly Poll","123 456 789","Drug1",3,"Dr. Peter",2.5,21 "Henny Penny","234 567 890","Drug2",1,"Dr. Pick",1.95,30 Print each prescription object using the str () special method Refill the prescription of the second object twice Print the second prescription object with updated refills using the special_str__() method Activate Winows. Print the person's name and the number of refills left for the first prescription object Print the total number of prescriptions objects created MCP: 234 567 890 Doclon's Name: Dr. Pick Drug: Drug2 Refills Left: 1 Total Bill: $67.27 Refills Left: 0 Sorry, there are no refills left. Person's Name: Henny Penny MGP#: 234 567 890 Doctor's Name: Dr. Pick Drug: Drug2 Refills left: 0 Total Bill: $67.27 Person's Name: Rolly Poll Number of refills left: 3 Total number of prescription objects: 2 Total cost of all Prescription Objects: $127.65 Hows. With your understanding of the problem statement above, complete the program code given below to generate the required output. Print the total number of prescriptions objects created Print the total cost of all prescription objects for one fill/refill of each, including dispensing fee For example, given the following as input "Rolly Poll","123 456 789","Drug1",3,"Dr. Peter",2.5,21 "Henny Penny","234 567 890","Drug2",1,"Dr. Pick",1.95,30 The output from the completed code should be as follows: Person's Name: Rolly Poll MCP#: 123 456 789 Doctor's Name: Dr. Peter Drug: Drugi Refills Left: 3 Total Bill: $60.37 Person's Name: Henny Penny MCP#: 234 567 890 With your understanding of the problem statement above, complete the program code given below to generate the required output. A class to keep track of prescriptions class Prescription: #Class Variables #LINE 1 #LINE 2 Constructor method that generates a Prescription object tassign values to the private instance variables: pName, #mcp, drugName, noofRefillsLeft, dName, dUnitcost, noofUnits det init (self, person, mcpNo, drug, refill, doctor, dost, units): person #LINE 3 = mcpNo #LINE 4 = drug #LINE 5 refill #LINE 6 doctor LINE 7 dcost #LINE 8 units #LINE 9 units #LINE 9 #update the class variables: Noof Prescriptions, TotalCost #LINE 10 Prescription. Totalcost += self.computeCost ( #Accessor method to get the name of the person #@return the pName def getPersonName( ): LINE 11 return #LINE 12 #Accessor method to get number of refills left #@return the number of refills left def getNoofRefillsLeft( ): #LINE 13 #LINE 14 #Mutator method to update the number of refills if a user wants a refill; #must check if the refill is possible and print message if it is not #or update number of refills and display new number of refills left if it is def refilltheprescription(self): if #LINE 15 print("Sorry, there are no refills left. ") else: #LINE 16 print ("Refills Left: %d " % ) #LINE 17 #Compute the cost of the drug including dispencing fee # @return the cost of the drug. #@return the cost of the drug def computeCosta ): #LINE 18 #Define the constant variable DISP_FEE #LINE 19 Cost #LINE 20 return cost str a #Special method to print the information about the #prescription including person's name, MCP number, doctor's #name, name of the drug, number of refills and the amount #to be paid for one fill/refill def str (self): return #LINE 21 # Define the main function def main(): #Create 2 prescription objects pl = #LINE 22 p2 #LINE 23 #print each prescription object using the special method #LINE 24 #LINE 25 #Request two refills for the second object p2. #LINE 26 p2. #LINE 27 #Print the second prescription object with updated #refills using the special method print (p2) #Print the person's name and the number of refills left #for the person from the first prescription object print #LINE 28 print #LINE 29 print () #Print the total number of prescription objects printl #LINE 30 #Print the total cost of all prescription objects for one fill/refill of each print #LINE 31 #call the main function main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started