有关类,可部分运行,但不能通过编译*******谢!
import java.text.*;public class Date
{
//类变量声明部分
private int month;
private int day;
private int year;
//类方法定义部分
Date()
{ //这是一个构造方法,因为它和类名相同
month = 7;
day = 4;
year = 2001;
System.out.println("From the default constructor:"+"\n Created a new date
object with data values"+"\n month="+month+"day="+day+"year="+year);
}
Date(int mm,int dd,int yyyy) //这是一个重载构造方法
{
month = mm;
day = dd;
year = yyyy;
System.out.println("From the default constructor:"+"\n Created a new date
object with data values"+"\n month="+month+"day="+day+"year="+year);
}
Date(long yyyymmdd) //第二个构造方法
{
year = int(yyyymmdd/10000.0); //抽取年
month = int((yyyymmdd - year*10000.0) / 100.0);
day = int(yyyymmdd - year * 10000.0 - month*100.0);
System.out.println("From the second overloaded constructor:"
+"\n Created a new Date object with data values"
+"\n month ="+ month + "day="+day "year="+year);
}
public void setDate(int mm,int dd,int yyyy)
{
month = mm;
day = dd;
year = yyyy;
}
public void showDate()
{
DecimalFormat df = new DecimalFormat("00");
System.out.println("The date is" +df.format(month) +'/'+df.format(day)
+ '/'+ df.format(year%100)); //精确到最后两位
}
{
Date a = new Date (); //声明一个Date类型的对象
Date b = new Date (5,1,2004);
Date c = new Date (20050915L);
}
}