onsider the scenario of a Pharmacy Management System. The following UML Class diagram shows a hierarchy of some of the classes in the system. (Shown in Picture) 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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter1: Creating Java Programs
Section: Chapter Questions
Problem 1DE
icon
Related questions
Question

Consider the scenario of a Pharmacy Management System. The following UML Class diagram shows a hierarchy of some of the classes in the system. (Shown in Picture)

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
+ changeStatet): void
Item
<cabstract>>
- id: int
- name: String
+ Item(id: int, name: String)
+tostring() : String
Invoiceltem
PrescriptionItem
potency: int
dose: int
CUrrentStatus: boolean
price: float
quantity: int
discount: float
- Availability: int
Prescriptionltemé potency: int, dose: int)
+ changeState(): void
+ reset(): void
+ Invoiceltem price: fleat, quantity: int)
+ changestate(): void
+ reset(): void
+ computePrice) : float
+ tostring() : String
Transcribed Image Text:<<interface>> StateManager + reset(): void + changeStatet): void Item <cabstract>> - id: int - name: String + Item(id: int, name: String) +tostring() : String Invoiceltem PrescriptionItem potency: int dose: int CUrrentStatus: boolean price: float quantity: int discount: float - Availability: int Prescriptionltemé potency: int, dose: int) + changeState(): void + reset(): void + Invoiceltem price: fleat, quantity: int) + changestate(): void + reset(): void + computePrice) : float + tostring() : String
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Software Development
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT