集册 Java实例教程 课堂作文示范

课堂作文示范

欢马劈雪     最近更新时间:2020-01-02 10:19:05

563
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
课堂作文示范

public class Main 

{
/* from 
N o w J a v a . c o m - 时代Java*/

   public static void main(String[] args)

   {

      Date birth = new Date(7, 24, 1949);

      Date hire = new Date(3, 12, 1988);

      Employee employee = new Employee("Bob", "Blue", birth, hire);


      System.out.println(employee); 

   } 

}

 class Date 

{

   private int month; // 1-12

   private int day; // 1-31 based on month

   private int year; // any year
/** from 时 代 J     a    v  a - nowjava.com**/

   private static final int[] daysPerMonth = 

      {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

   

   // constructor: confirm proper value for month and day given the year

   public Date(int month, int day, int year)

   {

      this.month = month;

      this.day = day;

      this.year = year;


      System.out.printf("Date object constructor for date %s%n", this);

   } 

   

   // return a String of the form month/day/year

   public String toString()

   { 

      return String.format("%d/%d/%d", month, day, year); 

   } 

}

 class Employee 

{

   private String firstName;

   private String lastName;

   private Date birthDate;

   private Date hireDate;


   // constructor to initialize name, birth date and hire date

   public Employee(String firstName, String lastName, Date birthDate, 

      Date hireDate)

   {

      this.firstName = firstName;

      
展开阅读全文