Write a complete Java program given the following UML class diagrams:
Pharmacy
|
- name: String
- medicines: ArrayList<Medicine>
|
+ Pharmacy (name:String, medicines: Medicine)
+ getName(): String
+ setName(n : String)
+ getMedicines (): Medicine
+ addMed(newMed : Medicine)
+ computePrices(): double
+ toString(): String
|
-------------------
Medicine |
- name: String
- code: int
- price: double
|
+ Medicine (n:String, c:int, p:double)
+ getName(): String
+ getCode(): int
+ getPrice(): double
+ setName(n : String)
+ setCode(c : int)
+ setPrice(p : double)
+ toString(): String
|
Class Pharmacy and class Medicine have “Has-a” relationship. An object of type Pharmacy may have more than one object of type Medicine.
* getMedicines () returns “medicines” of type ArrayList
* addMed() takes and object of type “Medicine” and add it to the “medicines” list.
* computePrices(): returns the total price of all medicines In the main method in your driver class:
* Define 2 objects of type “Medicine” and add them to an ArrayList, then use this list when creating an object of type “Pharmacy”.
* Define third object of type “Medicine” and use “addMedicine” function to add it to the pharmacy.
* Print the total price of all medicines The output may be as the following:
Medicine name: Contra, code: 1234, price: 22.75
Medicine name: Exylin, code: 5678, price: 6.0
Medicine name: Propolsaft, code: 9101, price: 49.5
Sum of all medicines = 78.25
|