LoganBlackisle

PN

Sep 15th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. package ordination;
  2.  
  3. import java.time.LocalDate;
  4. import java.time.temporal.ChronoUnit;
  5. import java.util.ArrayList;
  6.  
  7. public class PN extends Medication {
  8.     private double numberOfUnits;
  9.     private ArrayList<LocalDate> numberOfTimes = new ArrayList<>();
  10.     private Medicine medicine;
  11.  
  12.     public PN(LocalDate start, LocalDate end, Medicine medicine, double number) {
  13.         super(start, end, medicine);
  14.         this.numberOfUnits = number;
  15.         this.medicine = medicine;
  16.     }
  17.  
  18.     public ArrayList<LocalDate> getnumberOfTimes() {
  19.         return numberOfTimes;
  20.     }
  21.  
  22.     /**
  23.      * Register that a dosis have been given on the day givenThe
  24.      *
  25.      * @param givenThe
  26.      * @return true if givenThe is within the medications valid period, and the date is remembered. Else return false, and the date is ignored
  27.      */
  28.     public boolean givDosis(LocalDate givenThe) {
  29.         if (givenThe.isEqual(getStartDay()) || givenThe.isAfter(getStartDay()) && givenThe.isBefore(getEndDay())
  30.                 || givenThe.isEqual(getEndDay())) {
  31.             numberOfTimes.add(givenThe);
  32.             return true;
  33.         } else {
  34.             return false;
  35.         }
  36.     }
  37.  
  38.     public double dayDosis() {
  39.         LocalDate first = null;
  40.         LocalDate last = null;
  41.         if (numberOfTimes.isEmpty()) {
  42.             return 0.0;
  43.         }
  44.         for (LocalDate s : numberOfTimes) {
  45.             if (first == null || s.isBefore(first)) {
  46.                 first = s;
  47.             }
  48.             if (last == null || s.isAfter(first)) {
  49.                 last = s;
  50.             }
  51.         }
  52.         int numberofdays = (int) ChronoUnit.DAYS.between(first, last) + 1;
  53.         double daydosis = getNumberOfTimesGiven() * getNumberOfUnits() / numberofdays;
  54.         return daydosis;
  55.     }
  56.  
  57.     public double totalDosis() {
  58.         double totaldosis = getNumberOfTimesGiven() * getNumberOfUnits();
  59.         return totaldosis;
  60.     }
  61.  
  62.     public int getNumberOfTimesGiven() {
  63.         int numberoftimesint = 0;
  64.         for (LocalDate s : numberOfTimes) {
  65.             numberoftimesint++;
  66.         }
  67.         return numberoftimesint;
  68.     }
  69.  
  70.     public double getNumberOfUnits() {
  71.         return numberOfUnits;
  72.     }
  73.  
  74.     @Override
  75.     public Medicine getMedicine() {
  76.         return medicine;
  77.     }
  78.  
  79.     @Override
  80.     public String getType() {
  81.         return "PN";
  82.     }
  83. }
Add Comment
Please, Sign In to add comment