Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package eventplanner;
- /**
- *
- * @author joshua
- */
- public class Event
- {
- private int day;
- private int month;
- private int year;
- private int hour;
- private String agenda;
- private static int[] monthList=new int[13];
- private static int[] dayList=new int[32];
- private static int[] yearList=new int[201];
- private static int[] hourList=new int[24];
- /* Test Data for Debugging
- public static void main(String args[])
- {
- Event test = new Event(5,20,2013,-1,"Test");
- Event test2 = new Event(5,21,2013,4,"Test2");
- System.out.println(test.getEvent());
- System.out.println();
- System.out.println(test2.getEvent());
- }
- */
- public Event()
- {
- month=1;
- day=1;
- year=2001;
- hour=-1;
- agenda="Unknown";
- dayList[day]++;
- monthList[month]++;
- yearList[year-1900]++;
- }
- public Event(int month, int day, int year, int hour, String agenda)
- {
- this.month=month;
- this.day=day;
- this.year=year;
- this.hour=hour;
- this.agenda=agenda;
- dayList[this.day]++;
- monthList[this.month]++;
- yearList[this.year-1900]++;
- if(hour!=-1)
- {
- hourList[this.hour]++;
- }
- }
- public int getDay()
- {
- return day;
- }
- public int getMonth()
- {
- return month;
- }
- public int getYear()
- {
- return year;
- }
- public int getHour()
- {
- return hour;
- }
- public String getAgenda()
- {
- return agenda;
- }
- public String getEvent()
- {
- if(getHour()>=0)
- {
- return(getMonth() + " " + getDay() + " " + getYear() + " " + getHour() + "\n" + getAgenda());
- }
- else
- {
- return(getMonth() + " " + getDay() + " " + getYear() + "\n" + getAgenda());
- }
- }
- public static Event[] sortDates(Event[] event)
- {
- Event aDate=null;
- Event bDate=null;
- int stop=getEventLength(event);
- for(int i=0;i<stop-1;i++)
- {
- for(int j=0;j<stop-1;j++)
- {
- aDate=event[j];
- bDate=event[j+1];
- if(!aDate.isDateGreater(bDate))
- {
- event[j+1]=aDate;
- event[j]=bDate;
- }
- }
- }
- return event;
- }
- public boolean isDateGreater(Event event)
- {
- boolean greater=false;
- if(event!=null && this!=null)
- {
- if(event.year>this.year)
- {
- greater=true;
- }
- else if(event.year==this.year && event.month>this.month)
- {
- greater=true;
- }
- else if(event.year==this.year && event.month==this.month && event.day>this.day)
- {
- greater=true;
- }
- else if(event.year==this.year && event.month==this.month && event.day==this.day && event.hour>this.hour)
- {
- greater=true;
- }
- }
- return greater;
- }
- public static int getEventLength(Event[] event)
- {
- int count=0;
- for(int i=0;i<event.length;i++)
- {
- if(event[i]!=null)
- {
- count++;
- }
- }
- return count;
- }
- public String displayEvent()
- {
- if(getHour()>=0)
- {
- return(getMonth() + "/" + getDay() + "/" + getYear() + " " + "Hour: " + getHour() + "\n" + getAgenda());
- }
- else
- {
- return(getMonth() + "/" + getDay() + "/" + getYear() + " " + "\n" + getAgenda());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement