Question
I have some errors with my code, please help me fix them. The code of the resource class: import java.util.Scanner; /** A class to keep
I have some errors with my code, please help me fix them.
The code of the resource class:
import java.util.Scanner; /** A class to keep track of a single appointment. */ public class U9P03R { private String description; private int year; private int month; private int day;
/** Initializes appointment for a given date. @param year the year @param month the month @param day the day @param description the text description of the appointment */ public U9P03R(int year, int month, int day, String description) { this.year = year; this.month = month; this.day = day; this.description = description; }
public void process() { U9P03R[] appointments = new U9P03R[4]; appointments[0] = new Daily(2016, 1, 1, "Brush your teeth."); appointments[1] = new Monthly(2016, 1, 31, "Visit grandma."); appointments[2] = new Onetime(2016, 3, 3, "Dentist appointment."); appointments[3] = new Onetime(2016, 4, 2, "Trick or Treat."); System.out.println("Enter a date (year, month, day) to list " + "appointments: "); Scanner in = new Scanner(System.in); int year = in.nextInt(); int month = in.nextInt(); int day = in.nextInt(); for (int i = 0; i
/** Returns the year of the appointment. @return the year */ public int getYear() { return year; }
/** Returns the month of the appointment. @return the month */ public int getMonth() { return month; }
/** Returns the day of the appointment. @return the day */ public int getDay() { return day; } /** Determines if the appointment is on the date given. @param year the year to check @param month the month to check @param day the day to check @return true if the appointment matches all three parameters */ public boolean occursOn(int year, int month, int day) { return (year == this.year) && (month == this.month) && (day == this.day); }
/** Converts appointment to string description. */ public String toString() { return String; } /** A onetime appointment. */ class Onetime extends U9P03R { /** Initializes appointment for a given date. @param year the year @param month the month @param day the day @param description the text description of the appointment */ public Onetime(int year, int month, int day, String description) { super(year, month, day, description); } } /** Monthly appointment. */ class Monthly extends U9P03R { /** Initializes appointment for a given date. @param year the year @param month the month @param day the day @param description the text description of the appointment */ public Monthly(int year, int month, int day, String description) { super(year, month, day, description); } /** Determines if the appointment occurs on the same day of the month. @param year the year @param month the month @param day the day @return true if day matches the appointment date and is later than the base appointment */ public boolean occursOn(int year, int month, int day) { if (year getYear()) { return true; } if (year == getYear()) { if (month > getMonth()) { return true; } if (month == getMonth()) { if (day >= getDay()) { return true; } } } return false; } } }
The code of the driver class:
public class U9P03D { public static void main(String[] args) { U9P03R appointment = new U9P03R(); appointment.process(); } }
The errors:
/** Monthly appointment. */ class Monthly extends U9P03R /** Initializes appointment for a given date. @param year the year @param month the month @param day the day @param description the text description of the appointment */ public Monthly (int year, int month, int day, String description) super(year, month, day, description); 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 */ Determines if the appointment occurs on the same day of the month. @param year the year @param month the month @param day the day @return true if day matches the appointment date and is later than the base appointment U9E02D.java U9E01R.java U9E01D.java U8P13D.java U9E03R.java U9P01R.java U9E11R.java U9E11D.java U9P01D.java U9P02R.ja Compile Messages jGRASP Messages Run I/O Interactions End Clear Help ---jGRASP wedge2: exit code for process is 1. ---jGRASP: operation complete. --- jGRASP exec: java U9P03D Enter a date (year, month, day) to list appointments: Enter a date (year, month, day) to list appointments: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "U9P03R.getYear()" because "appoint" is null L at U9P03R$Monthly.occurson (U9P03R.java:129) at U9P03R.process(U9P03R.java:32) at U9P03D.main (U9P03D.java:5) ---jGRASP wedge2: exit code for process is 1. --- --jGRASP: operation complete.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started