The StateManager Interface is a generic interface which has two methods changeState (boolean : status). This method is used to change the status of InvoiceItem and PrescriptionItem. The possible status for InvoiceItem can be (Available – true or Unavailable - false), whereas PrescriptionItem has status (Recommended-true or Prohibited – false) passed to the method as an argument. The reset () method sets the default value for both InvoiceItem and PrescriptionItem. The Item class is self-explanatory. It implements the StateManager interface, and has toString method which prints the information in the following format. "Item Name: <> (<>)” e.g. Item Name: Panadol (223) Two classes PrescriptionItem and InvoiceItem are inherited from Item class representing the items that can be sold with doctor’s prescription and without prescription respectively with following functionalities: The constructors of PrescriptionItem and InvoiceItem initialize fields to appropriate parameters as shown in the diagram. Both PrescriptionItem and InvoiceItem classes will override the changeStatus Inside PrescriptionItem, it will set the value to available (true) or unavailable (flase), while in InvoiceItem class it will set value to recommended (true) or prohibited (false). However, the default value in both classes will be set to false. The computePrice method returns (does not print) the price of invoice item according to price, quantity and discount rate (percentage). The toString method of InvoiceItem class prints the invoice item in the following format. Item Name: <> (<>), Price: <> Quantity: <>Total: <> (@<> % discount) E.g., Item Name: Panadol (223), Price: 2, Quantity: 150, Total: 270 (@10 % discount) Finally, write a driver class named ItemTester to test the functionality of PrescriptionItem and InvoiceItem classes. Create at least two objects of each class polymorphically by initializing objects of subclasses to reference of a super class and print the details using toString method by iterating through the objects of both classes.
The StateManager Interface is a generic interface which has two methods changeState (boolean : status). This method is used to change the status of InvoiceItem and PrescriptionItem. The possible status for InvoiceItem can be (Available – true or Unavailable - false), whereas PrescriptionItem has status (Recommended-true or Prohibited – false) passed to the method as an argument. The reset () method sets the default value for both InvoiceItem and PrescriptionItem.
The Item class is self-explanatory. It implements the StateManager interface, and has toString method which prints the information in the following format.
"Item Name: <<name>> (<<id>>)” e.g. Item Name: Panadol (223)
- Two classes PrescriptionItem and InvoiceItem are inherited from Item class representing the items that can be sold with doctor’s prescription and without prescription respectively with following functionalities:
- The constructors of PrescriptionItem and InvoiceItem initialize fields to appropriate parameters as shown in the diagram.
- Both PrescriptionItem and InvoiceItem classes will override the changeStatus Inside PrescriptionItem, it will set the value to available (true) or unavailable (flase), while in InvoiceItem class it will set value to recommended (true) or prohibited (false). However, the default value in both classes will be set to false.
- The computePrice method returns (does not print) the price of invoice item according to price, quantity and discount rate (percentage).
- The toString method of InvoiceItem class prints the invoice item in the following format.
Item Name: <<name>> (<<id>>), Price: <<price>> Quantity: <<quantity>>Total:
<<computePrice()>> (@<<discount>> % discount)
E.g., Item Name: Panadol (223), Price: 2, Quantity: 150, Total: 270 (@10 % discount)
Finally, write a driver class named ItemTester to test the functionality of PrescriptionItem and InvoiceItem classes. Create at least two objects of each class polymorphically by initializing objects of subclasses to reference of a super class and print the details using toString method by iterating through the objects of both classes.
![<<interface>>
StateManager
+ reset(): void
+ changeState(): void
Item
<<abstract>>
- id: int
name: String
+ Item(id: int, name: String)
+toString(): String
InvoiceItem
PrescriptionItem
- price: float
- quantity: int
discount: float
-Availability: int
+ Invoiceltem(price: float, quantity: int)
+ changeState() : void
+ reset() : void
+ computePrice() : float
+toString): String
potency: int
dose: int
currentStatus: boolean
+ PrescriptionItem(potency: int, dose: int)
+ changeState(): void
+ reset(): void](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff006718d-f113-4dbf-ad7d-ffc09500a568%2F55412ca2-045a-4d07-8c7a-8b41abfbbe29%2F31gyp9_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)