-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
152 lines (137 loc) · 3.79 KB
/
Copy pathEvent.java
File metadata and controls
152 lines (137 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package hw1;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.time.LocalTime;
/**
* Event class represents an event containing several methods that can be used to
* to mutate the event object's variables or to access them
* @author BrandonAmazing
* @version 1.0
*/
public class Event implements Comparable<Event>
{
String name;
LocalDate date;
TimeInterval tInt;
/**
* Event - constructor for an event consisting of a name, date, and time interval
* @param name - the name of the event
* @param date - the date of the event
* @param tI - the time interval object of the event, containing a start and end time
*/
public Event(String name, LocalDate date,TimeInterval tI)
{
this.name = name;
this.date = date;
this.tInt = tI;
}
/**
* compareTo - compares one event object to another by first the date, and then the start time
* of the event if the dates are equal
* @param that - the event object to compare
* @return either a positive or negative integer stating if one event should come before or after another
*/
public int compareTo(Event that)
{
int DateCmp = this.getDate().compareTo(that.getDate());
if (DateCmp != 0)
{
return DateCmp;
}
return this.getTimeInterval().getStartTime().compareTo(that.getTimeInterval().getStartTime());
}
/**
* equals - checks if two objects are equal based on the compareTo method
* @param x - an object to be compared
* @return a boolean true or false depending on if two objects are equal
*/
public boolean equals(Object x)
{
Event that = (Event)x;
return this.compareTo(that) == 0;
}
/**
* getName - gets the name of the event object
* @return name, the name of the event
*/
public String getName()
{
return name;
}
/**
* setName - set desired name for an event
* @param n - the new name for the event
*/
public void setName(String n)
{
name = n;
}
/**
* getDate - gets the date of the event object
* @return date - the date of the event
*/
public LocalDate getDate()
{
return date;
}
/**
* setDate - sets the desired date of the new event object
* @param d - the new date of the event
*/
public void setDate(LocalDate d)
{
date = d;
}
/**
* getTimeInterval - gets the time interval of the event object
* @return tInt, the time interval of the event
*/
public TimeInterval getTimeInterval()
{
return tInt;
}
/**
* setTimeInterval - sets the time interval to desired interval
* @param s - the start time of the event
* @param e - the end time of the event
*/
public void setTimeInterval(LocalTime s, LocalTime e)
{
tInt = new TimeInterval(s, e);
}
/**
* printTimeInterval - prints the time interval of the event object with the start time
* followed by a dash and the end time
* @param t - the time interval to print
* @return the printed string of the time interval
*/
public String printTimeInterval(TimeInterval t)
{
return t.getStartTime().toString() + " - " + t.getEndTime().toString();
}
/**
* printDate - prints the date of the event in the format day of week,
* and then month, the day of month, and the year in integer form
*/
public void printDate()
{
DateTimeFormatter df = DateTimeFormatter.ofPattern("E, MMM d, yyyy");
System.out.println(df.format(date));
}
/**
* printEvent - prints the name of the event and start and end time of the event
*/
public void printEvent()
{
System.out.println(name + " " + this.printTimeInterval(tInt));
}
/**
* printEventListFormat - prints the date of the event followed by the time interval
* and then the event's name
*/
public void printEventListFormat()
{
DateTimeFormatter df = DateTimeFormatter.ofPattern("eeee MMMM d");
System.out.println(" " + df.format(date) + " " + this.printTimeInterval(tInt) + " " + this.name);
}
}