Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me find my error/s. I am lost as I know what the problem is but not

ID: 3799605 • Letter: P

Question

Please help me find my error/s. I am lost as I know what the problem is but not sure how to fix it.

Problem: Exception in thread "main" java.lang.Error: Unresolved compilation problems:
   The method getNumberofdays() is undefined for the type Year
   The method getNumberofdays() is undefined for the type LeapYear

   at UseYear.main(UseYear.java:11)

UseYear.java

public class UseYear
{
public static void main(String args[])
{
    //Initializing class
      Year year = new Year();
    //Calling method to display days
    year.getNumberofdays();

    //Initializing class
    LeapYear leapyear = new LeapYear();
    //Calling to display days
    leapyear.getNumberofdays();
}
}

LeapYear.java

public class LeapYear extends Year
{
   //Constructor for LeapYear class
   public LeapYear()
{
   setNumberofdays(366);
}
}

Year.java

public class Year
{
   //Variable
   int numberofdays;
  
   public void getNumberofdays
   {
       System.out.println(numberofdays);
   }
   //Method to set the value
   public void setNumberofdays(int numberofdays)
   {
       this.numberofdays = numberofdays;
    }
   //Constructor for Year class
   public Year()
   {
       setNumberofdays(365);       
   }
}     

UseYear2.java

public class UseYear2
{
public static void main(String args[])
{
   int day = 2, month = 3;
   //Initializing class
    Year2 year = new Year2();
   //Initializing class
    LeapYear2 leapyear = new LeapYear2();
    //Display days elapsed
    System.out.println("Days elapsed in a Year: " + year.daysElapsed(day, month));
    System.out.println("Days elapsed in a Leap Year: " + leapyear.daysElapsed(day, month));
}
}

LeapYear2.java

public class LeapYear extends Year
{
   //Constructor for class
   public LeapYear2()
   {
       //Setting number of days
       setNumberofdays(366);
   }
   //Method to get end value
   public int daysElapsed(int day, int month)
   {
       int temp = 0;
       for (int i = 1; i < month;i++);
       {
           if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
           {
               temp += 31;
           }
           else if (i == 4 || i == 6 || i == 9 || i == 11)
           {
               temp += 30;
           }
           else if (i == 2)
           {
               temp += 29;
           }
       }
       temp += day;
       return temp;
   }  
}

Year2.java

public class Year2
{
      int numberofdays;
  
      public void getNumberofdays()
      {
          System .out.println(numberofdays);
      }
      public void setNumberofdays(int numberofdays)
      {
          this.numberofdays = numberofdays;
      }
      public Year2()
      {
          setNumberofdays(365);
      }
      public int daysElapsed(int day, int month)
      {
          int temp = 0;
           for (int i = 1; i < month;i++);
           {
               if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
               {
                   temp += 31;
               }
               else if (i == 4 || i == 6 || i == 9 || i == 11)
               {
                   temp += 30;
               }
               else if (i == 2)
               {
                   temp += 28;
               }
           }
           temp += day;
           return temp;       
      }
}

Explanation / Answer

HI, I have fixed all error.

Please let me know in case of any issue.

######## Year.java #######

public class Year

{

   //Variable

   private int numberofdays;

   //Constructor for Year class

   public Year()

   {

       setNumberofdays(365);

   }

   public int getNumberofdays()

   {

       return numberofdays;

   }

   //Method to set the value

   public void setNumberofdays(int numberofdays)

   {

       this.numberofdays = numberofdays;

   }

}

################## LeapYear.java ############

public class LeapYear extends Year

{

   //Constructor for class

   public LeapYear()

   {

       //Setting number of days

       setNumberofdays(366);

   }

   //Method to get end value

   public int daysElapsed(int day, int month)

   {

       int temp = 0;

       for (int i = 1; i < month;i++)

       {

           if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)

           {

               temp += 31;

           }

           else if (i == 4 || i == 6 || i == 9 || i == 11)

           {

               temp += 30;

           }

           else if (i == 2)

           {

               temp += 29;

           }

       }

       temp += day;

       return temp;

   }

}

######### UseYear.java ###############

public class UseYear

{

   public static void main(String args[])

   {

       //Initializing class

       Year year = new Year();

       //Calling method to display days

       System.out.println(year.getNumberofdays());

       //Initializing class

       LeapYear leapyear = new LeapYear();

       //Calling to display days

       System.out.println(leapyear.getNumberofdays());

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote