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 :

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; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!