-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointmentDemo.java
More file actions
39 lines (32 loc) · 1.4 KB
/
Copy pathAppointmentDemo.java
File metadata and controls
39 lines (32 loc) · 1.4 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
package appointment;
import java.util.Scanner;
public class AppointmentDemo {
public static void main(String[] args) {
// scanner object to take user inputs
Scanner scanner = new Scanner(System.in);
// an array for holding the appointments
Appointment[] appointments = new Appointment[3];
// creating appointments
DailyAppointment dailyAppointment = new DailyAppointment("Family visit");
MonthlyAppointment monthlyAppointment = new MonthlyAppointment("Dentist", 5);
YearlyAppointment yearlyAppointment = new YearlyAppointment("Get overall check-up", 2022, 5, 5);
// adding appointments to the array
appointments[0] = dailyAppointment;
appointments[1] = monthlyAppointment;
appointments[2] = yearlyAppointment;
// asking for input (date)
System.out.print("Enter year: ");
int year = scanner.nextInt();
System.out.print("Enter month: ");
int month = scanner.nextInt();
System.out.print("Enter day: ");
int day = scanner.nextInt();
// for each appointment
for (Appointment appointment: appointments) {
// if there is appointment on this day then print it
if (appointment.occursOn(year, month, day)) {
System.out.println(appointment.getTitle());
}
}
}
}