我试图在构造函数中使用一个对象,该对象是我的日期类。我不确定,但认为我应该使用界面。
public class Date {
private int day;
private int month;
private int year;
public Date(int day, int month, int year) {
this.year = year;
checkMonth(month);
checkDay(day);
}
public void checkMonth(int monthIn)
{
if(monthIn < 1 || monthIn > 12)
{
System.out.print("the month is invalid");
}
else
{
month = monthIn;
}
}
public void checkDay(int dayIn)
{
if(dayIn < 1 || dayIn > 31)
{
System.out.print("the day is invalid and has been set to 1");
day = 1;
}
else
{
day = dayIn;
}
}
public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
public String toString()
{
return "birth date: " + getDay() + "/" + getMonth() + "/" + getYear();
}
}
和一个 Employee 类(最后的 public void add() 只是反复试验,不确定它是否应该在那里)
public abstract class Employee {
private String fName;
private String lName;
private int rsiNumber;
private Date DOB;
public Employee(String fName, String lName, int rsiNumber, Date DOB)
{
this.fName = fName;
this.lName = lName;
this.rsiNumber = rsiNumber;
this.DOB = DOB;
}
public String getFName()
{
return fName;
}
public String getLanme()
{
return lName;
}
public int getRsiNumber()
{
return rsiNumber;
}
public Date getDOB()
{
return DOB;
}
public void setFName(String fNameIn)
{
fName = fNameIn;
}
public void setLName(String lNameIn)
{
lName = lNameIn;
}
public void setRsiNumber(int rsiNumIn)
{
rsiNumber = rsiNumIn;
}
public void setDOB(Date DOBIn)
{
DOB = DOBIn;
}
public String toString()
{
return null;
}
public void add(Date x)
{
DOB = x;
}
}
连同 Employee 的其他一些子类。我试图在 Employee 的构造函数中使用 Date 作为对象,但是当我创建我的 Test 类时,我收到一个错误,指出尚未定义构造函数。
最近几天我从大学生病了,不知道如何让它发挥作用。
这是我的测试
public class Test {
public static void main(String [] args)
{
Employee employees[] ={
new Salaried("Joe", "Bloggs", "R5457998", 6, 15, 1944, 800.00 ),
new Hourly( "Kate", "Wyse", "S6657998", 10, 29, 1960, 16.75, 40 ),
new Commission("Jim", "Slowe", "K5655998", 9, 8, 1954, 10000, .06 )};
}
}