Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.time.*;
- public class Medicine {
- private String name;
- private Date start;
- private Date end;
- private int freq;
- public Medicine(String name, Date start, Date end, int freq){
- this.name = name;
- this.start = start;
- this.end = end;
- this.freq = freq;
- }
- public Medicine(String name, Date start){//for no end date
- this.name = name;
- this.start = start;
- this.end = new Date(0);
- this.freq = -1;
- }
- public void setName(String name){
- this.name = name;
- }
- public void setStart(Date start){
- this.start = start;
- }
- public void setEnd(Date end){
- this.end = end;
- }
- public void setFreq(int freq){
- this.freq = freq;
- }
- public String getName(){
- return name;
- }
- public Date getStart(){
- return start;
- }
- public Date getEnd(){
- return end;
- }
- public int getFreq(){
- return freq;
- }
- public static void main (String[] args) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date start = calendar.getTime();
- calendar.add(Calendar.DATE, 2);
- Date end = calendar.getTime();
- //Medicine p0 = new Medicine(name, start);
- Medicine p1 = new Medicine("Brian Moreno", start, end, 8);
- scheduleReminder(p1.getStart(), p1.getEnd(), p1.getName(), p1.getFreq());
- }
- public static void scheduleReminder(Date start, Date end, String name, int freq){
- Date current = start;
- Calendar c = Calendar.getInstance();
- c.setTime(current);
- if(freq == -1){
- }
- else{
- int hours = 24 / freq;
- while(end.compareTo(current) > 0){
- System.out.println(current + " Please take your dose.");
- c.add(Calendar.HOUR,hours);
- current = c.getTime();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement