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.
Step by step
Solved in 2 steps with 1 images