Advertisement
Guest User

Medicine Class

a guest
Nov 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import java.util.*;
  2. import java.time.*;
  3.  
  4. public class Medicine {
  5. private String name;
  6. private Date start;
  7. private Date end;
  8. private int freq;
  9.  
  10.  
  11.  
  12. public Medicine(String name, Date start, Date end, int freq){
  13. this.name = name;
  14. this.start = start;
  15. this.end = end;
  16. this.freq = freq;
  17. }
  18.  
  19. public Medicine(String name, Date start){//for no end date
  20. this.name = name;
  21. this.start = start;
  22. this.end = new Date(0);
  23. this.freq = -1;
  24. }
  25.  
  26.  
  27. public void setName(String name){
  28. this.name = name;
  29. }
  30.  
  31. public void setStart(Date start){
  32. this.start = start;
  33. }
  34.  
  35. public void setEnd(Date end){
  36. this.end = end;
  37. }
  38.  
  39. public void setFreq(int freq){
  40. this.freq = freq;
  41. }
  42.  
  43. public String getName(){
  44. return name;
  45. }
  46.  
  47. public Date getStart(){
  48. return start;
  49. }
  50.  
  51. public Date getEnd(){
  52. return end;
  53. }
  54.  
  55. public int getFreq(){
  56. return freq;
  57. }
  58.  
  59. public static void main (String[] args) {
  60. Calendar calendar = Calendar.getInstance();
  61. calendar.set(Calendar.HOUR_OF_DAY, 0);
  62. calendar.set(Calendar.MINUTE, 0);
  63. calendar.set(Calendar.SECOND, 0);
  64. calendar.set(Calendar.MILLISECOND, 0);
  65. Date start = calendar.getTime();
  66. calendar.add(Calendar.DATE, 2);
  67. Date end = calendar.getTime();
  68.  
  69.  
  70. //Medicine p0 = new Medicine(name, start);
  71. Medicine p1 = new Medicine("Brian Moreno", start, end, 8);
  72. scheduleReminder(p1.getStart(), p1.getEnd(), p1.getName(), p1.getFreq());
  73.  
  74. }
  75.  
  76. public static void scheduleReminder(Date start, Date end, String name, int freq){
  77. Date current = start;
  78. Calendar c = Calendar.getInstance();
  79. c.setTime(current);
  80. if(freq == -1){
  81.  
  82. }
  83. else{
  84. int hours = 24 / freq;
  85. while(end.compareTo(current) > 0){
  86. System.out.println(current + " Please take your dose.");
  87. c.add(Calendar.HOUR,hours);
  88. current = c.getTime();
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement