Created
March 22, 2022 20:22
-
-
Save Pzdrs/91fa619aa7aa4b6cc931c7d0f41a82b0 to your computer and use it in GitHub Desktop.
antibiotics scheduler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param args [0] - Total amount of pills - i.e. 21 | |
| * [1] - Hourly period - i.e. 8 | |
| * [2] - First dose (military standard) - i.e. 1430 => 14:30, ... | |
| * [3] (optional) - Offset - you don't have time to wait to fit in to your schedule from the beginning, | |
| * each dose will be delayed by this number (in minutes) - i.e. 15 | |
| */ | |
| public static void main(String[] args) { | |
| int firstDose = Integer.parseInt(args[2]); | |
| int period = Integer.parseInt(args[1]); | |
| int offset = args.length > 3 ? Integer.parseInt(args[3]) : 0; | |
| int[] lastDose = {firstDose / 100, firstDose % 100}; | |
| System.out.printf("Dosage: %d pills/day (every %d hours)\nFirst dose: %s:%s\nOffset: %dmin\n\n", | |
| 24 / period, period, format(lastDose[0]), format(lastDose[1]), offset); | |
| for (int i = 0; i < Integer.parseInt(args[0]); i++) { | |
| System.out.printf("Dose #%d: %s:%s\n", i + 1, format(lastDose[0]), format(lastDose[1])); | |
| lastDose[0] += period; | |
| lastDose[1] += offset; | |
| if (lastDose[0] > 24) lastDose[0] = lastDose[0] - 24; | |
| if (lastDose[1] > 60) { | |
| lastDose[0]++; | |
| lastDose[1] = lastDose[1] - 60; | |
| } else if (lastDose[1] == 60) { | |
| lastDose[0]++; | |
| lastDose[1] = 0; | |
| } | |
| } | |
| } | |
| public static String format(int i) { | |
| return i == 24 || i == 0 ? "00" : String.valueOf(i); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment