Java 将用户输入与数组与布尔值进行比较

Java 将用户输入与数组与布尔值进行比较,java,arrays,boolean,subclass,superclass,Java,Arrays,Boolean,Subclass,Superclass,这是我收到的作业 实现一次、每天和每月的超类预约和子类预约。预约有一个描述(例如,“看牙医”),发生在一个或多个日期。编写一个方法occursOn(int year、int month、int day),检查约会是否发生在该日期。例如,对于每月约会,必须检查该月的日期是否匹配。然后用约会的混合物填充约会对象数组。让用户输入日期并打印出该日期发生的所有约会 我认为把我搞砸的部分就是这一部分 每个子类中都有一个方法,用于检查约会是否发生在该日期(一次性)、日期(天)或月份(月)。要求用户输入要检查的

这是我收到的作业

实现一次、每天和每月的超类预约和子类预约。预约有一个描述(例如,“看牙医”),发生在一个或多个日期。编写一个方法occursOn(int year、int month、int day),检查约会是否发生在该日期。例如,对于每月约会,必须检查该月的日期是否匹配。然后用约会的混合物填充约会对象数组。让用户输入日期并打印出该日期发生的所有约会

我认为把我搞砸的部分就是这一部分

每个子类中都有一个方法,用于检查约会是否发生在该日期(一次性)、日期(天)或月份(月)。要求用户输入要检查的日期。根据用户选择的内容,每个子类中的占用者应运行并显示任何匹配的约会和相关描述。对于一次性子类,占用人需要三个输入(年、月和日)进行验证;对于日子类,占用人需要一个输入(日)进行验证;对于月子类,占用人需要一个输入(月)进行验证。占用人对于不同的子类是不同的

这是我的超类

class Appointment{
private int year;
private int month;
private int day;
private String description;
public Appointment(int day, int month, int year, String description){
    this.year = year;
    this.month = month;
    this.day = day;
    this.description = description;
}

public int getYear(){
    return year;
}

public int getMonth(){
    return month;
}

public int getDay(){
    return day;
}

public boolean occursOn(int day, int month, int year){
    return (day == this.day) && (month == this.month) && (year == this.year);
}

public String toString(){
    return description;
}}
子类:

class Daily extends Appointment
{
public Daily(int day, int month, int year, String description)
{
    super(day, month, year, description);
}

@Override
public boolean occursOn(int year, int month, int day)
{
    if(getDay() == day) return true;
    return false;
}}

class Monthly extends Appointment
{
public Monthly(int year, int month, int day, String description)
{
    super(year, month, day, description);
}

public boolean occursOn(int year, int month, int day)
{
    if((getDay() == day) && ((getMonth() == month))) return true;
    return false;
}}

class Onetime extends Appointment
{
public Onetime(int year, int month, int day, String description)
{
    super(year, month, day, description);
}

@Override
 public boolean occursOn(int day, int month, int year){
    return (getDay() == day) && (getMonth() == month) && (getYear() == year);
   }}
使用此方法,我如何将用户输入与提供的数组进行比较,并与每个子类的方法占用者进行比较

import java.util.Scanner;
class AppointmentDemo
{
public static void main(String[] args)
{
Appointment[] appointment = new Appointment[5];
    appointment[0] = new Onetime(25, 12, 2017,"Root Canal");
    appointment[1] = new Monthly(25, 12, 2017, "Teeth cleaning");
    appointment[2] = new Daily(25, 12, 2017, "Filling");
    appointment[3] = new Onetime(13, 12, 2017, "Crown");
    appointment[4] = new Monthly(15, 4, 2017, "Dentures");

//ask user for input
Scanner keyboard = new Scanner(System.in);
//day
System.out.println("Please enter the day of your appointment.");
int day = keyboard.nextInt();
//Month
System.out.println("Please enter the month of your appointment.");
int month = keyboard.nextInt();
//Year
System.out.println("Please enter the year of your appointment.");
int year = keyboard.nextInt();

for (int i = 0; i < appointment.length; i++)
{
  if (appointment[i].occursOn(year, month, day)==true)
  {
    System.out.println(("You have an appointment for ") + appointment[i].toString() + " on " + day +     "/"+ month + "/" + year);
  }
}}} 
import java.util.Scanner;
班级任命演示
{
公共静态void main(字符串[]args)
{
任命[]任命=新任命[5];
任命[0]=新的一次性(2017年12月25日,“根管”);
预约[1]=新的每月(2017年12月25日,“牙齿清洁”);
任命[2]=新日报(2017年12月25日,“填写”);
任命[3]=新的一次性任命(2017年12月13日,“官方”);
任命[4]=新的每月(2017年4月15日,“假牙”);
//请求用户输入
扫描仪键盘=新扫描仪(System.in);
//一天
System.out.println(“请输入约会日期”);
int day=keyboard.nextInt();
//月
System.out.println(“请输入您约会的月份。”);
int month=keyboard.nextInt();
//年
System.out.println(“请输入您的约会年份”);
int year=keyboard.nextInt();
for(int i=0;i