import java.awt.*; public class MedicationBar { String label; double medicationLevel, maxMedicationLevel; int xOfBottom, yOfBottom; public MedicationBar(String label, int x, int y, double medL, double maxMedL) { this.label = label; this.xOfBottom = x; this.yOfBottom = y; this.medicationLevel = medL; this.maxMedicationLevel = maxMedL; } public String display(Graphics g) { g.setColor(Color.black); g.drawRect(xOfBottom, yOfBottom-(int)maxMedicationLevel, 20, (int)maxMedicationLevel); g.drawString(label, xOfBottom, yOfBottom + 18); g.setColor(Color.red); g.fillRect(xOfBottom+1, yOfBottom-(int)medicationLevel+1, 19, (int)medicationLevel-1); medicationLevel-=(maxMedicationLevel/900); if (medicationLevel < 0) { return "You forgot your medication!"; } else if (medicationLevel > maxMedicationLevel) { return "You've overdosed!"; } else return ""; } public void addMedication(int totNum) { medicationLevel+=(medicationLevel/(totNum/2)); } }