Question: using java Consider the Stack data structure implementation to implement a Pharmacy stack of medicine. You need to implement the following classes: 1) class Medicine



Consider the Stack data structure implementation to implement a Pharmacy stack of medicine. You need to implement the following classes: 1) class Medicine that includes the following data members private String name; // Medicine name private int mediD: Forder medicine id private int totalltems; total Items private Medicine next; The class should have the following: A constructor that initializes the instance variables name, totalltems and med/D. Set and get methods for each instance variable. 2) class Pharmacy Stack that includes the following instance variables: private Medicine top: private String pharmacyName: private int numorOrder; The class should have the following methods: A constructor that initializes the market name pharmacy Name and sets numorOrder to 0. public boolean push(String name, int items) creates a Medicine using numOfOrder as the mediD and adds a Medicine in the stack. public void printo private void pusho public Medicine popo public int stackSize() Counts how many medicines are in stack. Returns the count public int sum Items publie Medicine popo public int stackSize Counts how many medicines are in stack. Returns the count. public int sumItems Returns the sum of the totalltems in the stack public double average Calculates the average of the totalltems in the stack and returns its value. 3) Write a test application named Exam Test. In the main method, display a menu of options as shown in the sample output: Choice 1: Ask the user to enter the medicine information and call method push. If the method returns false, display an error message "Error adding medicine". Choice 2: Call method print Choice 3: Ask the user to enter the Medicine name and call method stackSite and print the result. Choice 4: Call method sumltems and print the result. Choice 5: Call method average and peint the result Choice 6: Exit the program. Sample Output Please enter the pharmacy name Royal pharmacy Choose 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit Enter the medicine name: Panadol Enter the total items: Choose 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 1 1 T Royal pharmacy Choose: 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 1 Enter the medicine name: Panadol Enter the total items: Choose: 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 1 Enter the medicine name: Augmentine Enter the total items: 10 Choose: 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 1 Enter the medicine name: Strepsils Enter the total items: Choose: 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 2 1. Medicine name: Panadol. Order Number 1. Total Items 2. Medicine name: Augustine Onder Number 2 Total des 10 3. Medicine name: Strepsils, Order Number: 1. Totalem Choose: 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 3 Medicine stack siis Choose 1. Add a Medicine Choose 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit 1. Melicine nam Padel Order Number: 1 Total: 2. Medicine namene, Order Number: 2. Total time: 10 3. Medicine am Strepsils Order Number 3. Total len 4 Choose 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit Medicine stack size is Choose I. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit + Total items in stack is 19 Choose: 1. Add a Medicine 2. Print all Medicines 3. Find stack size 4. Sum of items 5. Find average 6. Exit Average Number of six 6.333 Choose: L. Add a Medicine 2. Print all Medicines 3. Find stack stre 4. Sum of items 5. Find average 6. Exit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
