class Personnel
{
 private int id;
 private int phone;
 private Date birthday;
 private int income;
 private static int count;

 public Personnel(int i, int p, int m, int d, int y, int in)
 {
  this.id =i;
  phone=p;

  birthday=new Date(m,d,y);
  check(in);
  count++;
 }

 public static int getPersonnelcount()
 {return count;}

 


  //檢查收入是否小於0
 public void check(int in)
 {
  if (in<0)
     income=0;
  else
     income=in;
 }

 public void printPersonnel ()
 {
  System.out.println("客戶資料:");
  System.out.println("編號:"+ id);
  System.out.println("電話:"+ phone);
  System.out.println("生日:");
  birthday.printDate();
  System.out.println("收入:"+ income);
 }

}

 

class Date   // Date類別宣告
{  // 成員資料
   private int day;
   private int month;
   private int year;
   // 建構子: 使用參數設定成員資料初始值
   public Date(int m, int d, int y)
   {  if ( !setDate(m, d, y) )
      {  day = 1;                // 設定日期
         month = 5;              // 設定月份
         year = 2004;            // 設定年份
      }
   }
   // 成員方法: 檢查日期資料
   private boolean validDate(int m, int d, int y)
   {  // 檢查日期資料是否在範圍內
      if ( d < 1 || d > 31 ) return false;
      if ( m < 1 || m > 12 ) return false;
      if ( y < 1900 ) return false;  // 不在範圍內
      return true;                 // 合法的日期資料
   }
   // 成員方法: 設定日期資料
   public boolean setDate(int month, int day, int year)
   {  // 檢查時間參數是否合法
      if ( validDate(month, day, year) )
      {  this.day = day;          // 設定日期
         this.month = month;      // 設定月份
         this.year = year;        // 設定年份
         return true;             // 設定成功
      }
      else return false;          // 設定失敗
   }
   // 成員方法: 顯示日期資料
   public void printDate()
   {  // 輸出成員資料的月, 日和年
      System.out.println(month+"-"+day+"-"+year);
   }
}

public class joyjava10251
{
 public static void main(String[] args)
 {
  Personnel c1=new Personnel(1,'L',1,15,1967,2100);
  Personnel c2=new Personnel(2,'H',5,25,1978,-1);

  c1.printPersonnel();
  c2.printPersonnel();
 }
}


--執行結果--

客戶資料:
編號:1
電話:76
生日:
1-15-1967
收入:2100
客戶資料:
編號:2
電話:72
生日:
5-25-1978
收入:0


arrow
arrow
    全站熱搜

    Joy 發表在 痞客邦 留言(0) 人氣()