我是java中的新手,我需要帮助我的方法。java - 将数组写入输出文件
所以我需要创建flagOverdueOwners(CarOwner [] inArray)方法,该方法为注册已过期的车辆生成并返回一个数组。这被定义为超过12个月基于当前REG_MONTH这是4 REG_YEAR这为2014年5
注册,所以这是在RegistrationMethods类我flagOverdueOwners方法:
public class RegistrationMethods implements Serializable{
final int REG_MONTH = 4;
final int REG_YEAR = 2014;
public CarOwner[] flagOverdueOwners(CarOwner[] inArray)
{
// insert code to compare that are earlier than 4/2013
temp = inArray;
return temp;}
}
,这是我的主方法:
public static void main (String [] args)
{
PrintWriter outputStream = null;
outputStream = new PrintWriter (new FileOutputStream ("output.txt", true));
CarOwner arr[] = dmv.flagOverdueOwners(ItStateCopy)
outputStream.println("\nOwners with Expired Registration");
for (int i = 0 ; i < arr.length ; i++)
{
outputStream.println(arr[i]);
}
outputStream.close();
}
我output.txt的应conatin:
业主过期的注册
袋獾STU-789二千零十二分之一十
西尔威斯特猫NQR-456二千〇一十三分之一
约塞米蒂萨姆FGH-123二千〇一十三分之三
(并且有4个后列表中的一束/ 2013)
ps.this是我CarOwner类:
public class CarOwner extends Citizen implements CarOwnerInterface, Serializable, Comparable
{
private String license;
private int month, year;
public CarOwner()
{
super();
license = "Not Assigned";
month = 0;
year = 0;
}
public CarOwner(String inFirst, String inLast, String inLicense, int inMonth, int inYear)
{
super(inFirst, inLast);
license = inLicense;
month = inMonth;
year = inYear;
}
public void setLicense(String inLicense)
{
license = inLicense;
}
public String getLicense()
{
return license;
}
public void setMonth(int inMonth)
{
month = inMonth;
}
public int getMonth()
{
return month;
}
public void setYear(int inYear)
{
year = inYear;
}
public int getYear()
{
return year;
}
public int compareTo(Object o)
{
if ((o != null) && (o instanceof CarOwner))
{
CarOwner otherOwner = (CarOwner) o;
if (otherOwner.getYear() > getYear())
return -1;
else if (otherOwner.getYear() < getYear())
return 1;
else if (otherOwner.getMonth() > getMonth())
return -1;
else if (otherOwner.getMonth() < getMonth())
return 1;
else
return 0;
}
return -1;
}
public String toString()
{
String str;
str = getLastName() +" " + getFirstName() + "\t\t" + license + "\t\t" + month + "/" + year;
return str;
}
}
,我应该如何代码来COMPAR任何想法e如果日期早于2013年4月?
任何帮助或建议将不胜感激!