⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program9_4.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
import java.text.*;   // needed for formatting
public class Date
{
  // class variable declaration section
  private int month;
  private int day;
  private  int year;
  // class method definition section
  Date()   // this is a constructor method because it has the same
  {        // name as the class
    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)  // this is an overloaded constructor
  {
    month = mm;
    day = dd;
    year = yyyy;
    System.out.println("From the first overloaded constructor:"
       + "\n  Created a new Date object with data values"
       + "\n    month = " + month + "  day  = " + day + "  year = " + year);
  }
  Date(long yyyymmdd)   // here is the second overloaded constructor
  {
    year = (int)(yyyymmdd/10000.0);    // extract the year
    month = (int)( (yyyymmdd - year * 10000.0)/100.00 );  // extract the month
    day = (int)(yyyymmdd - year * 10000.0 - month * 100.0); // extract the day
    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)); // extract the last 2 year digits
  }
  public static void main(String[] args)
  {
    Date a = new Date();   // declare an object
    Date b = new Date(5,1,2004);   // declare an object
    Date c = new Date(20050915L);  // declare an object
  }
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -