【Java】一個Employee類的實際使用


public class EmployeeTest {
    public static void main(String[] args) 
    {
     //構造一個Employee數組,並填入三個雇員對象  Employee[] staff
= new Employee[3]; staff[0] = new Employee("菠蘿",75000,1998,11,12); staff[1] = new Employee("蘿卜",65000,1999,11,12); staff[2] = new Employee("朵朵",85000,1998,3,8); //對每個雇員的薪資提高5% for(Employee e : staff) e.rasieSalary(5);
     //打印所有雇員的信息
for(Employee e : staff) System.out.println("name="+e.getName()+",salary="+e.getSalary()+",hireDay"+e.getHireDay()); } } import java.time.LocalDate; class Employee { private String name; private double salary; private LocalDate hireDay; public Employee(String n,double s,int year,int month,int day) { name= n; salary = s; hireDay = LocalDate.of(year, month, day); } public String getName() { return name; } public double getSalary() { return salary; } public LocalDate getHireDay() { return hireDay; } public void rasieSalary(double byPercent) { double raise = salary * byPercent / 100; salary += raise; } }


 

 

這個程序中包含兩個類:Employee類和帶有public訪問修飾符的EmployeeTest類。EmployeeTest類包含了main方法。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM