0% found this document useful (0 votes)
10 views8 pages

Pharmacy Health Medicare System Code

Uploaded by

nulhakimluqman25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Pharmacy Health Medicare System Code

Uploaded by

nulhakimluqman25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

BufferedReader;

import [Link];

import [Link];

import [Link];

import [Link];

//main class

public class PharmacyHMSystem {

public static void main(String[] args) {

// Create a BufferedReader for user input

BufferedReader reader = new BufferedReader(new InputStreamReader([Link]));

// Initialize variables

int totalBill = 0;

try {

// Pharmacy Health Medicare System

[Link]("\t\t\t\t Pharmacy Health Medicare System");

[Link]("\t\t\t-----------------------------------------------------");

// Medicine Inventory //to store data

Map<String, Medicine> medicineInvt = new HashMap<>();

[Link]("Paracetamol", new OverTheCounterMedicine("Paracetamol", 15, 10));

[Link]("Indapamine", new OverTheCounterMedicine("Indapamine", 25, 19));

[Link]("Antacids", new OverTheCounterMedicine("Antacids", 52, 23));

[Link]("Insulin", new PrescriptionMedicine("Insulin", 50, 36));


[Link]("Vitamin C", new VitaminMedicine("Vitamin C", 50, 40));

// Display available medicines with stock and price

[Link]("\n\t\t\t\tAvailable Medicines:");

[Link]("\t\t\t\tCode\tMedicine\tStock\tPrice");

int Mcode = 1;

for ([Link]<String, Medicine> entry : [Link]()) {

Medicine medicine = [Link]();

[Link]("\t\t\t\t" + Mcode + "\t" + [Link]() + "\t" +

[Link]() + "\tRM" + [Link]());

Mcode++;

[Link]();

// Ask user for medicine selection and quantity

[Link]("\t\t\t\tEnter medicine code or name: ");

String selectedMedicineInput = [Link]();

Medicine selectedMedicine = getMedicine(selectedMedicineInput, medicineInvt);

if (selectedMedicine != null) {

[Link]("\t\t\t\tEnter quantity: ");

int quantityMed = [Link]([Link]());

// Check if requested quantity is available in stock

int availableStock = [Link]();

if (quantityMed <= availableStock) {

// Calculate total bill

int bill = [Link]() * quantityMed;

totalBill += bill;

// Update stock
[Link](availableStock - quantityMed);

[Link]("\t\t\t\tMedicine added to the bill.");

[Link]("\t\t\t\tTotal Bill: RM" + totalBill);

// Ask user if they want to add more medicines

[Link]("\t\t\t\tDo you want to add more medicines? (yes='Y'/no='N'): ");

String choice = [Link]();

while ([Link]("Y")) {

// Display available medicines with stock and price

[Link]("\n\t\t\t\tAvailable Medicines:");

[Link]("\t\t\t\tCode\tMedicine\tStock\tPrice");

Mcode = 1;

for ([Link]<String, Medicine> entry : [Link]()) {

Medicine medicine = [Link]();

[Link]("\t\t\t\t" + Mcode + "\t" + [Link]() + "\t" +

[Link]() + "\tRM" + [Link]());

Mcode++;

[Link]();

[Link]("\t\t\t\tEnter medicine code or name: ");

selectedMedicineInput = [Link]();

selectedMedicine = getMedicine(selectedMedicineInput, medicineInvt);

if (selectedMedicine != null) {

[Link]("\t\t\t\tEnter quantity: ");

quantityMed = [Link]([Link]());

// Check if requested quantity is available in stock


availableStock = [Link]();

if (quantityMed <= availableStock) {

// Calculate total bill

bill = [Link]() * quantityMed;

totalBill += bill;

// Update stock

[Link](availableStock - quantityMed);

[Link]("\t\t\t\tMedicine added to the bill.");

[Link]("\t\t\t\tTotal Bill: RM" + totalBill);

[Link]("\t\t\t\tDo you want to add more medicines? (yes='Y'/no='N'):


");

choice = [Link]();

} else {

[Link]("\t\t\t\tQuantity stock is not available.");

break;

} else {

[Link]("\t\t\t\tInvalid medicine code or name.");

break;

// Totaling (calculation)

[Link]("\t\t\t\tEnter amount of payment: ");

int payment = [Link]([Link]());

if (payment < totalBill) {

[Link]("\t\t\t\tInsufficient payment amount. Please provide the correct


amount.");
} else {

int balance = payment - totalBill;

[Link]("\t\t\t\tBalance: RM" + balance);

} else {

[Link]("\t\t\t\tQuantity stock is not available.");

} else {

[Link]("\t\t\t\tInvalid medicine code or name.");

} catch (IOException e) {

[Link]();

private static Medicine getMedicine(String input, Map<String, Medicine> medicineInvt) {

Medicine selectedMedicine = null;

if ([Link]("\\d+")) {

int selectedMCode = [Link](input);

selectedMedicine = getMedicineByMCode(selectedMCode,
[Link]().toArray(new Medicine[0]));

} else {

selectedMedicine = [Link](input);

return selectedMedicine;

private static Medicine getMedicineByMCode(int Mcode, Medicine[] medicines) {


if (Mcode >= 1 && Mcode <= [Link]) {

return medicines[Mcode - 1];

[Link]("\t\t\t\tThank you for using Pharmacy Health Medicare System!");

return null;

//Superclass

class Medicine {

private String name;

private int stock;

private int price;

public Medicine(String name, int stock, int price) {

[Link] = name;

[Link] = stock;

[Link] = price;

public String getName() {

return name;

public int getStock() {

return stock;

public void setStock(int stock) {

[Link] = stock;

}
public int getPrice() {

return price;

//subclasses

class PrescriptionMedicine extends Medicine {

private String prescriptionCode;

public PrescriptionMedicine(String name, int stock, int price, String prescriptionCode) {

super(name, stock, price);

[Link] = prescriptionCode;

public String getPrescriptionCode() {

return prescriptionCode;

class OverTheCounterMedicine extends Medicine {

public OverTheCounterMedicine(String name, int stock, int price) {

super(name, stock, price);

class AntibioticMedicine extends PrescriptionMedicine {

public AntibioticMedicine(String name, int stock, int price, String prescriptionCode) {

super(name, stock, price, prescriptionCode);

}
class VitaminMedicine extends OverTheCounterMedicine {

public VitaminMedicine(String name, int stock, int price) {

super(name, stock, price);

Common questions

Powered by AI

Exception handling in the PharmacyHMSystem is implemented using try-catch blocks around code sections that might generate IOException due to user input operations. The IOException is caught and handled by printing the stack trace for debugging purposes, preventing the system from crashing due to unhandled input errors. This allows the system to manage errors gracefully and maintain its functionality, thus improving the robustness of user interaction features .

Polymorphism in the PharmacyHMSystem is evident in how different subclasses of Medicine can be used interchangeably within the inventory management system. This allows the system to treat various types of medicines uniformly when adding, retrieving, and manipulating medicine data. For example, whether an object is an instance of PrescriptionMedicine or VitaminMedicine, the system can invoke methods like getName or getPrice without needing to know the specific subclass at compile time. This flexibility supports code generalization and enhances the system's ability to integrate and manage diverse medicine types efficiently .

Inheritance is a key design principle in the PharmacyHMSystem, employed to classify medicines into hierarchical categories with shared properties. The Medicine class acts as a superclass, defining common attributes such as name, stock, and price. Subclasses like OverTheCounterMedicine, PrescriptionMedicine, and VitaminMedicine extend Medicine to introduce additional attributes or enhance existing properties. PrescriptionMedicine, for instance, adds a prescriptionCode attribute. This approach allows new types of medicines to be added with minimal code modifications, promoting code reuse and scalability within the system .

The PharmacyHMSystem handles insufficient payments by checking if the user-provided amount is less than the total bill and prompting the user to provide the correct amount if necessary. For stock unavailability, it checks if the requested quantity exceeds available stock and notifies the user that the desired quantity is not available, prompting them to enter a valid quantity. These mechanisms ensure transactions are valid and reinforcing system robustness by preventing erroneous or incomplete operations .

The system uses a HashMap to manage the medicine inventory, with medicine names as keys and Medicine objects (or its subclasses) as values. This structure is efficient for inventory management due to its average O(1) time complexity for both insertions and lookups, which is suitable for systems that require quick access to randomly stored elements, such as medicines identified by code or name. By using an object model, it allows for easy extension of characteristics relevant to different medicine types, enhancing the system's flexibility and maintainability .

The PharmacyHMSystem uses a hierarchy of classes to manage different types of medicines. Medicines are stored in a HashMap, where the key is the medicine name and the value is an instance of the Medicine class or its subclasses. The Medicine class serves as a superclass, and specialized subclasses like OverTheCounterMedicine, PrescriptionMedicine, and VitaminMedicine are used to manage specific attributes pertinent to those medicine types. This design allows for the extension of new medicine categories with specific features, fostering flexibility and scalability in the system .

The total bill in the PharmacyHMSystem is calculated by multiplying the price per unit of the selected medicine by the quantity specified by the user. Each successful transaction adds to the total bill, ensuring dynamic and accumulative billing for multiple purchases within a session. The system updates these calculations whenever a new medicine is added to the purchase, and this amount is displayed to the user, along with checks made between available stock and requested quantities to ensure validity of each transaction .

Improvements to the PharmacyHMSystem's user interaction flow could include implementing a graphical user interface (GUI) to enhance usability and visual appeal. Adding user input validation to ensure valid entries for medicine codes and quantities could prevent errors at runtime. Enhancing payment processing with options for digital payments and confirmations could improve transaction efficiency. Additionally, implementing feedback mechanisms such as history and recommendations based on past purchases could personalize the user experience further, and integrating AI to assist users in case of uncertainties could significantly enhance overall satisfaction .

The system uses a BufferedReader to capture user input. Users can select medicines by entering a code or the name of the medicine. Once a medicine is selected, the system prompts the user to enter the desired quantity. It then checks the stock availability and processes the purchase if the stock is sufficient. The total bill is calculated based on the price of the selected medicine and the quantity. If the user wishes to add more medicines, the process repeats until they finalize the purchase. The system also handles payment and calculates any balance if the provided payment exceeds the total bill .

While HashMap offers efficient average time complexity for operations, it faces limitations such as non-deterministic iteration order, which might not be suitable for applications requiring order-sensitive operations. It also provides no inherent synchronization for concurrent modifications, posing challenges for multi-threaded access. In the context of PharmacyHMSystem, this might be problematic in large-scale deployments needing thread safety and snapshot consistency during inventory updates. Additionally, it lacks the ability to store duplicate keys, which restricts its versatility when handling medicines with potentially similar names or synonyms .

You might also like