-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
289 lines (251 loc) · 11.6 KB
/
Main.java
File metadata and controls
289 lines (251 loc) · 11.6 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import java.util.*;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
class Event {
String name;
LocalDate date;
LocalTime time;
String note;
public Event(String name,LocalDate date,LocalTime time, String note) {
this.name=name;
this.date=date;
this.time=time;
this.note=note;
}
}
class CalendarPro{
Map<String, List<Event>> events;
public CalendarPro(){
events=new HashMap<>();
}
public void addEvent(String category, Event event){
events.computeIfAbsent(category, k -> new ArrayList<>()).add(event);
}
public void viewEvents(String category){
if (events.containsKey(category)){
System.out.println("events in category: "+category);
List<Event> categoryEvents=events.get(category);
System.out.println("******************************************************************");
System.out.println("Category Name Date Time Note");
System.out.println("------------------------------------------------------------------");
for (Event event : categoryEvents){
System.out.println(category+" "+event.name+" "+event.date+" "+ event.time+" "+event.note);
}
}
}
public void viewAllEvents(){
System.out.println("All Events:");
for (String category : events.keySet()) {
viewEvents(category);
}
}
public void viewtoday(){
LocalDate today = LocalDate.now();
System.out.println("events for today (" +today+"):");
System.out.println("******************************************************************");
System.out.println("Category Name Date Time Note");
System.out.println("------------------------------------------------------------------");
for(String category : events.keySet()) {
for(Event event : events.get(category)) {
if(event.date.equals(today)) {
System.out.println(category+" "+event.name+" "+event.date+" "+ event.time+" "+event.note); }
}
}
}
public void viewmonth(int month) {
System.out.println("events for month "+month+":");
System.out.println("******************************************************************");
System.out.println("Category Name Date Time Note");
System.out.println("------------------------------------------------------------------");
for(String category : events.keySet()) {
for(Event event : events.get(category)) {
if(event.date.getMonthValue()==month) {
System.out.println(category+" "+event.name+" "+event.date+" "+ event.time+" "+event.note); }
}
}
}
public void viewyear(int year){
System.out.println("events for year " +year+":");
System.out.println("******************************************************************");
System.out.println("Category Name Date Time Note");
System.out.println("------------------------------------------------------------------");
for (String category : events.keySet()) {
for (Event event : events.get(category)) {
if (event.date.getYear()==year) {
System.out.println(category+" "+event.name+" "+event.date+" "+ event.time+" "+event.note); }
}
}
}
public void smartSchedule(Event event, String category) {
LocalDate eventDate = event.date;
for (List<Event> categoryEvents : events.values()) {
for (Event existingEvent : categoryEvents) {
if (existingEvent.date.equals(eventDate)) {
System.out.println("An event is already scheduled on "+eventDate+".please choose a different date.");
return;
}
}
}
addEvent(category,event);
System.out.println("event smart scheduled successfully!");
}
}
class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
CalendarPro Cpro=new CalendarPro();
while(true){
System.out.println("------------------------------------------------------------------");
System.out.println("Welcome to CalendarPro:");
System.out.println("choose option:");
System.out.println("1.add Event");
System.out.println("2.view all Events or view by cateogory");
System.out.println("3.view events by today,month,year(easy viewing)");
System.out.println("4.smart schedule(before add check is event already present on that day)");
System.out.println("5.exit");
System.out.println("------------------------------------------------------------------");
System.out.print("select an option: ");
int choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.println("select a category:");
System.out.println("1.Health\n2.work\n3.personal\n4.meet\n5.other");
int cChoice = sc.nextInt();
sc.nextLine();
String scatgry;
if(cChoice==1) {
scatgry = "Health";
}
else if(cChoice==2) {
scatgry = "work";
}
else if(cChoice==3) {
scatgry = "personal";
}
else if(cChoice==4) {
scatgry = "meet";
}
else if(cChoice==5) {
scatgry="other";
}
else{
scatgry="other";
}
System.out.print("enter event name: ");
String name=sc.nextLine();
System.out.print("enter event date (dd-MM-yyyy): ");
String dateString=sc.nextLine();
DateTimeFormatter dformatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
LocalDate date=LocalDate.parse(dateString, dformatter);
System.out.print("enter event time (HH:mm): ");
LocalTime time=LocalTime.parse(sc.nextLine(), DateTimeFormatter.ofPattern("HH:mm"));
System.out.print("enter event note: ");
String note=sc.nextLine();
Event event=new Event(name,date,time,note);
Cpro.addEvent(scatgry, event);
System.out.println("event added successfully to category: "+scatgry);
break;
case 2:
System.out.println("1. view all events");
System.out.println("2. view events by categry");
System.out.print("select an option: ");
int vChoice=sc.nextInt();
sc.nextLine();
if(vChoice==1) {
Cpro.viewAllEvents();
}
else if(vChoice==2) {
System.out.print("select a category option: ");
System.out.println("1.Health,2.Work,3.personal,4.meet,5.other");
cChoice=sc.nextInt();
sc.nextLine();
if(cChoice==1) {
scatgry="Health";
}
else if(cChoice==2){
scatgry="Work";
}
else if(cChoice==3){
scatgry="personal";
}
else if(cChoice==4){
scatgry="meet";
}
else if(cChoice == 5){
scatgry="other";
}
else{
scatgry="other";
}
Cpro.viewEvents(scatgry);
} else{
System.out.println("Invalid choice.");
}
break;
case 3:
System.out.println("1.view events by today");
System.out.println("2.view events by month");
System.out.println("3.view events by year");
System.out.print("select an option: ");
int t=sc.nextInt();
sc.nextLine();
switch (t) {
case 1:
Cpro.viewtoday();
break;
case 2:
System.out.print("enter month (1-12): ");
int month=sc.nextInt();
Cpro.viewmonth(month);
break;
case 3:
System.out.print("enter year: ");
int year = sc.nextInt();
Cpro.viewyear(year);
break;
default:
System.out.println("invalid choice.");
}
break;
case 4:
System.out.println("select a category:");
System.out.println("1.Health\n2.work\n3.personal\n4.meet\n5.other");
cChoice = sc.nextInt();
sc.nextLine();
if(cChoice==1) {
scatgry="Health";
} else if(cChoice==2){
scatgry = "work";
} else if(cChoice==3){
scatgry="personal";
} else if(cChoice==4){
scatgry="meet";
} else if(cChoice==5){
scatgry="other";
} else{
scatgry="other";
}
System.out.print("enter event name: ");
name=sc.nextLine();
System.out.print("enter event date (dd-MM-yyyy): ");
dateString=sc.nextLine();
dformatter=DateTimeFormatter.ofPattern("dd-MM-yyyy");
date = LocalDate.parse(dateString, dformatter);
System.out.print("enter event time (HH:mm): ");
time=LocalTime.parse(sc.nextLine(), DateTimeFormatter.ofPattern("HH:mm"));
System.out.print("enter event note: ");
note=sc.nextLine();
Event smartScheduledEvent = new Event(name,date,time,note);
Cpro.smartSchedule(smartScheduledEvent, scatgry);
break;
case 5:
System.out.println("exiting CalendarPro");
System.exit(0);
default:
System.out.println("Invalid choice. Please select a valid option.");
}
}
}
}