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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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)

  1. 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:
    1. The constructors of PrescriptionItem and InvoiceItem initialize fields to appropriate parameters as shown in the diagram.  
    2. 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.                                                                             
    3. The computePrice method returns (does not print) the price of invoice item according to price, quantity and discount rate (percentage).       
    4. 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
Transcribed Image Text:<<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
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY