Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ordination;
- import java.time.LocalDate;
- import java.time.temporal.ChronoUnit;
- import java.util.ArrayList;
- public class PN extends Medication {
- private double numberOfUnits;
- private ArrayList<LocalDate> numberOfTimes = new ArrayList<>();
- private Medicine medicine;
- public PN(LocalDate start, LocalDate end, Medicine medicine, double number) {
- super(start, end, medicine);
- this.numberOfUnits = number;
- this.medicine = medicine;
- }
- public ArrayList<LocalDate> getnumberOfTimes() {
- return numberOfTimes;
- }
- /**
- * Register that a dosis have been given on the day givenThe
- *
- * @param givenThe
- * @return true if givenThe is within the medications valid period, and the date is remembered. Else return false, and the date is ignored
- */
- public boolean givDosis(LocalDate givenThe) {
- if (givenThe.isEqual(getStartDay()) || givenThe.isAfter(getStartDay()) && givenThe.isBefore(getEndDay())
- || givenThe.isEqual(getEndDay())) {
- numberOfTimes.add(givenThe);
- return true;
- } else {
- return false;
- }
- }
- public double dayDosis() {
- LocalDate first = null;
- LocalDate last = null;
- if (numberOfTimes.isEmpty()) {
- return 0.0;
- }
- for (LocalDate s : numberOfTimes) {
- if (first == null || s.isBefore(first)) {
- first = s;
- }
- if (last == null || s.isAfter(first)) {
- last = s;
- }
- }
- int numberofdays = (int) ChronoUnit.DAYS.between(first, last) + 1;
- double daydosis = getNumberOfTimesGiven() * getNumberOfUnits() / numberofdays;
- return daydosis;
- }
- public double totalDosis() {
- double totaldosis = getNumberOfTimesGiven() * getNumberOfUnits();
- return totaldosis;
- }
- public int getNumberOfTimesGiven() {
- int numberoftimesint = 0;
- for (LocalDate s : numberOfTimes) {
- numberoftimesint++;
- }
- return numberoftimesint;
- }
- public double getNumberOfUnits() {
- return numberOfUnits;
- }
- @Override
- public Medicine getMedicine() {
- return medicine;
- }
- @Override
- public String getType() {
- return "PN";
- }
- }
Add Comment
Please, Sign In to add comment