Full Coding
Full Coding
BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
//main class
// Initialize variables
int totalBill = 0;
try {
System.out.println("\t\t\t-----------------------------------------------------");
System.out.println("\n\t\t\t\tAvailable Medicines:");
System.out.println("\t\t\t\tCode\tMedicine\tStock\tPrice");
int Mcode = 1;
Mcode++;
System.out.println();
if (selectedMedicine != null) {
totalBill += bill;
// Update stock
selectedMedicine.setStock(availableStock - quantityMed);
while (choice.equalsIgnoreCase("Y")) {
System.out.println("\n\t\t\t\tAvailable Medicines:");
System.out.println("\t\t\t\tCode\tMedicine\tStock\tPrice");
Mcode = 1;
Mcode++;
System.out.println();
selectedMedicineInput = reader.readLine();
if (selectedMedicine != null) {
quantityMed = Integer.parseInt(reader.readLine());
totalBill += bill;
// Update stock
selectedMedicine.setStock(availableStock - quantityMed);
choice = reader.readLine();
} else {
break;
} else {
break;
// Totaling (calculation)
} else {
} else {
} catch (IOException e) {
e.printStackTrace();
if (input.matches("\\d+")) {
selectedMedicine = getMedicineByMCode(selectedMCode,
medicineInvt.values().toArray(new Medicine[0]));
} else {
selectedMedicine = medicineInvt.get(input);
return selectedMedicine;
return null;
//Superclass
class Medicine {
this.name = name;
this.stock = stock;
this.price = price;
return name;
return stock;
this.stock = stock;
}
public int getPrice() {
return price;
//subclasses
this.prescriptionCode = prescriptionCode;
return prescriptionCode;
}
class VitaminMedicine extends OverTheCounterMedicine {