Advertisement
junebug217

Event - Part of the Event Planner Application

Apr 1st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.99 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package eventplanner;
  6.  
  7. /**
  8.  *
  9.  * @author joshua
  10.  */
  11. public class Event
  12. {
  13.    
  14.     private int day;
  15.     private int month;
  16.     private int year;
  17.     private int hour;
  18.     private String agenda;
  19.     private static int[] monthList=new int[13];
  20.     private static int[] dayList=new int[32];
  21.     private static int[] yearList=new int[201];
  22.     private static int[] hourList=new int[24];
  23.    
  24.     /* Test Data for Debugging
  25.  
  26.     public static void main(String args[])
  27.     {
  28.         Event test = new Event(5,20,2013,-1,"Test");
  29.         Event test2 = new Event(5,21,2013,4,"Test2");
  30.         System.out.println(test.getEvent());
  31.         System.out.println();
  32.         System.out.println(test2.getEvent());
  33.     }
  34.     */
  35.    
  36.     public Event()
  37.     {
  38.         month=1;
  39.         day=1;
  40.         year=2001;
  41.         hour=-1;
  42.         agenda="Unknown";
  43.         dayList[day]++;
  44.         monthList[month]++;
  45.         yearList[year-1900]++;
  46.     }
  47.    
  48.     public Event(int month, int day, int year, int hour, String agenda)
  49.     {
  50.         this.month=month;
  51.         this.day=day;
  52.         this.year=year;
  53.         this.hour=hour;
  54.         this.agenda=agenda;
  55.         dayList[this.day]++;
  56.         monthList[this.month]++;
  57.         yearList[this.year-1900]++;
  58.         if(hour!=-1)
  59.         {
  60.             hourList[this.hour]++;
  61.         }
  62.        
  63.     }
  64.    
  65.     public int getDay()
  66.     {
  67.         return day;
  68.     }
  69.    
  70.     public int getMonth()
  71.     {
  72.         return month;
  73.     }
  74.    
  75.     public int getYear()
  76.     {
  77.         return year;
  78.     }
  79.    
  80.     public int getHour()
  81.     {
  82.         return hour;
  83.     }
  84.    
  85.     public String getAgenda()
  86.     {
  87.         return agenda;
  88.     }
  89.    
  90.     public String getEvent()
  91.     {
  92.         if(getHour()>=0)
  93.         {
  94.             return(getMonth() + " " + getDay() + " " + getYear() + " " + getHour() + "\n" + getAgenda());
  95.         }
  96.         else
  97.         {
  98.             return(getMonth() + " " + getDay() + " " + getYear() + "\n" + getAgenda());
  99.         }
  100.     }
  101.    
  102.     public static Event[] sortDates(Event[] event)
  103.     {
  104.         Event aDate=null;
  105.         Event bDate=null;
  106.         int stop=getEventLength(event);
  107.         for(int i=0;i<stop-1;i++)
  108.         {
  109.             for(int j=0;j<stop-1;j++)
  110.             {
  111.                 aDate=event[j];
  112.                 bDate=event[j+1];
  113.                 if(!aDate.isDateGreater(bDate))
  114.                 {
  115.                     event[j+1]=aDate;
  116.                     event[j]=bDate;
  117.                 }
  118.             }
  119.         }
  120.         return event;
  121.     }
  122.    
  123.     public boolean isDateGreater(Event event)
  124.     {
  125.         boolean greater=false;
  126.         if(event!=null && this!=null)
  127.         {
  128.             if(event.year>this.year)
  129.             {
  130.                 greater=true;
  131.             }
  132.             else if(event.year==this.year && event.month>this.month)
  133.             {
  134.                 greater=true;
  135.             }
  136.             else if(event.year==this.year && event.month==this.month && event.day>this.day)
  137.             {
  138.                 greater=true;
  139.             }
  140.             else if(event.year==this.year && event.month==this.month && event.day==this.day && event.hour>this.hour)
  141.             {
  142.                 greater=true;
  143.             }
  144.         }
  145.         return greater;
  146.     }
  147.    
  148.     public static int getEventLength(Event[] event)
  149.     {
  150.         int count=0;
  151.         for(int i=0;i<event.length;i++)
  152.         {
  153.             if(event[i]!=null)
  154.             {
  155.                 count++;
  156.             }
  157.         }
  158.         return count;
  159.     }
  160.    
  161.     public String displayEvent()
  162.     {
  163.         if(getHour()>=0)
  164.         {
  165.             return(getMonth() + "/" + getDay() + "/" + getYear() + " " + "Hour: " + getHour() + "\n" + getAgenda());
  166.         }
  167.         else
  168.         {
  169.             return(getMonth() + "/" + getDay() + "/" + getYear() + " " + "\n" + getAgenda());
  170.         }
  171.     }
  172.    
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement