내 IncDate 클래스는 내 일 이내 클래스를 확장합니다. 내 IncDate 클래스를 사용하여 다음 날을 나타내는 increment 메서드를 만들려고합니다. 그러나 난 바로 구현하고 옆에있는이 오류가 발생하고 수정 찾을 수 없습니다. 이 오류는 저를 말하고있다 : 그들은 내 DaysBetween 클래스 내에서 전달 된 사실에있을 때 슈퍼 생성자 구현은 주어진 유형에 적용 할 수 없습니다
Constructor DaysBetween in class DaysBetween cannot be applied to given types;
required:no arguments
found:int,int,int
reason:actual and formal argument lists differ in length
왜 오류가 인수가 필요하지 않습니다 것을 말하고있다. 확장 클래스가 자신의 생성자를 전달해야한다는 것을 알고 있습니다. 하지만 그게 내가
슈퍼과 함께하려고하는 것입니다. 그러면 오류가 발생하는 이유는 무엇입니까? 내
DaysBetween 클래스는 오류없이 작동하지만 명확하게 무언가가 내
IncDate 클래스에 영향을줍니다. 그래서 내 안에서 무엇이 내려다 보입니까
DaysBetween 확장에 영향을 미치는 클래스
IncDate 클래스?
DaysBetween 등급 :
package dateclass1;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Scanner;
class DateClass {
protected int year;
protected int month;
protected int day;
public static final int MINYEAR = 1583;
// Constructor
public DateClass(int newMonth, int newDay, int newYear)
{
month = newMonth;
day = newDay;
year = newYear;
}
// Observers
public int getYear()
{
return year;
}
public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public int lilian()
{
// Returns the Lilian Day Number of this date.
// Precondition: This Date is a valid date after 10/14/1582.
//
// Computes the number of days between 1/1/0 and this date as if no calendar
// reforms took place, then subtracts 578,100 so that October 15, 1582 is day 1.
final int subDays = 578100; // number of calculated days from 1/1/0 to 10/14/1582 November 17, 1858
int numDays;
// Add days in years.
numDays = year * 365;
// Add days in the months.
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month - 1) * 31) - ((4 * (month-1) + 27)/10);
// Add days in the days.
numDays = numDays + day;
// Take care of leap years.
numDays = numDays + (year/4) - (year/100) + (year/400);
// Handle special case of leap year but not yet leap day.
if (month < 3)
{
if ((year % 4) == 0) numDays = numDays - 1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % 400) == 0) numDays = numDays - 1;
}
// Subtract extra days up to 10/14/1582.
numDays = numDays - subDays;
return numDays;
}
@Override
public String toString()
// Returns this date as a String.
{
String monthString = new DateFormatSymbols().getMonths()[month-1];
return(monthString + "/" + day + "/" + year);
}
public class mjd
{
public int mjd()
{
final int subDays = 678941;
int numDays;
numDays = year * 365;
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month -1) * 31) - ((4 * (month-1) + 27)/10);
numDays = numDays + day;
numDays = numDays + (year/4) - (year/100) + (year/400);
if (month < 3)
{
if ((year % 4) == 0) numDays = numDays -1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % 400) == 0) numDays -= numDays -1;
}
// Days subtracted up to 10/14/1582
numDays = numDays - subDays;
return numDays;
}
}
public class djd
{
public int djd()
{
final int subDays = 693961; // number of calculated days from 1/1/0 to January 1,1900
int numDays;
// Add days in years.
numDays = year * 365;
// Add days in the months.
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month - 1) * 31) - ((4 * (month-1) + 27)/10);
// Add days in the days.
numDays = numDays + day;
// Take care of leap years.
numDays = numDays + (year/4) - (year/100) + (year/400);
// Handle special case of leap year but not yet leap day.
if (month < 3)
{
if ((year % 4) == 0) numDays = numDays - 1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % 400) == 0) numDays = numDays - 1;
}
// Subtract extra days up to 10/14/1582.
numDays = numDays - subDays;
return numDays;
}
}
}
public class DaysBetween
{
public static void main(String[] args)
{
Scanner conIn = new Scanner(System.in);
int day, month, year;
System.out.println("Enter two 'modern' dates: month day year");
System.out.println("For example, January 12, 1954, would be: 1 12 1954");
System.out.println();
System.out.println("Modern dates occur after " + DateClass.MINYEAR + ".");
System.out.println();
System.out.println("Enter the first date:");
month = conIn.nextInt();
day = conIn.nextInt();
year = conIn.nextInt();
DateClass date1 = new DateClass(month, day, year);
System.out.println("Enter the second date:");
month = conIn.nextInt();
day = conIn.nextInt();
year = conIn.nextInt();
DateClass date2 = new DateClass(month, day, year);
if ((date1.getYear() <= DateClass.MINYEAR)
||
(date2.getYear() <= DateClass.MINYEAR))
System.out.println("You entered a 'pre-modern' date.");
else
{
System.out.println("The number of days between");
System.out.print(date1);
System.out.print(" and ");
System.out.print(date2);
System.out.print(" is ");
System.out.println(Math.abs(date1.lilian() - date2.lilian()));
}
}
}
IncMain 등급 :
package dateclass1;
import java.util.Calendar;
/**
*
* @author macbookpro
*/
class IncDate extends DaysBetween {
public IncDate(int newMonth, int newDay, int newYear)
{
super(newMonth, newDay, newYear);
}
public void increment()
{
if(month == 1){
if(day>30){
day=1;
month=2;
}
else{
day=day+1;
}
}
else if (month == 2){
if ((year%4 == 0 && year%100 !=0) || year%400 == 0)
{
if(day>28){
day = 1;
month=3;
}
else{
day = day +1;
}
}
else{
if(day > 27){
day = 1;
month = 3;
}
else{
day = day + 1;
}
}
}
else if(month == 3){
if(day > 30){
day=1;
month=4;
}
else{
day = day + 1;
}
}
else if (month == 4){
if(day > 29){
day = 1;
month = 5;
}
else{
day = day + 1;
}
}
else if (month ==5){
if(day>30){
day = 1;
month= 6;
}
else{
day = day +1;
}
}
else if (month==6){
if(day>29){
day = 1;
month=7;
}
else{
day = day + 1;
}
}
else if (month==7){
if (day>30){
day = 1;
month = 8;
}
else{
day = day +1;
}
}
else if (month==8){
if (day>30){
day = 1;
month = 9;
}
else{
day = day + 1;
}
}
else if (month==9){
if (day>29){
day = 1;
month = 10;
}
else{
day = day + 1;
}
}
else if (month==10){
if (day>30){
day = 1;
month = 11;
}
else{
day = day + 1;
}
}
else if (month==11){
if (day>29){
day = 1;
month = 12;
}
else{
day = day + 1;
}
}
else if (month==12){
if (day>30){
day = 1;
month = 1;
year = year+1;
}
else{
day = day + 1;
}
}
}
}
이 내 프로그램에서 버그를 많이하지만이 버그는 그라운드 제로 인 것처럼 내가 생각합니다. 도와주세요.
3 개의 인수를 취하는'DaysBetween'에 생성자가 없습니다. –
잘못된 수업을 연장하고 있습니다. 'IncDate'는'DateClass'를 확장해야합니다. 'DaysBetween'이 아닙니다. (그냥 메인 메서드입니다.) –
감사합니다. 고마워요. 고마워요. –