首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

Java 物件導向練習:Employee 員工類別完整實作範例

     編輯:程式設計疑難解答

Employee 類別

package com.njupt.www;

import java.util.Date;

public class Employee {
    private int num;
    private String name;
    private String position;
    private String date;
    private float basicSalary;
    private float award;

    public Employee() { super(); }

    public Employee(int num, String name, String position, String date,
                    float basicSalary, float award) {
        this.num = num;
        this.name = name;
        this.position = position;
        this.date = date;
        this.basicSalary = basicSalary;
        this.award = award;
    }

    // Getter / Setter 略...

    public float getSalary() {
        return basicSalary + award;
    }

    @Override
    public String toString() {
        return "Employee [num=" + num + ", name=" + name +
               ", position=" + position + ", date=" + date +
               ", salary=" + getSalary() + "]";
    }
}

測試類別

package com.njupt.www;

public class Test {
    public static void main(String[] args) {
        Employee emp = new Employee(1001, "李雷", "經理", "2016-04-15", 8000, 2000);
        System.out.println(emp.toString());
    }
}

輸出

Employee [num=1001, name=李雷, position=經理, date=2016-04-15, salary=10000.0]
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved