? 在这个示例程序中包含两个类:Employee类和带有public访问修饰符的j类
运行截图:
?源代码:
package Joey1; import java.time.*; public class j { ?? ?public static void main(String args[]) ?? ?{ ?? ??? ?Employee[] staff = new Employee[3];//构造三雇员数组 ?? ??? ?staff[0] = new Employee("Andy Lau",100000,2001,11,28); ?? ??? ?staff[1] = new Employee("Eason Chen",900000,2000,11,28); ?? ??? ?staff[2] = new Employee("Haley Xc",200000,2002,11,16); ?? ??? ?for(Employee g:staff) ?? ??? ?{ ?? ??? ??? ?g.raiseSalary(50);//薪水提高50% ?? ??? ?} ?? ??? ?for(Employee g:staff) ?? ??? ??? ?System.out.println("name = "+g.getName()+",salary = "+g.getSalary()+",hireDay = "+g.getHireDay()); ?? ?} } class Employee//类别建立 { ?? ?private String name; ?? ?private double salary; ?? ?private LocalDate hireDay; ?? ?public Employee(String n,double s,int year,int mouth,int day) ?? ?{ ?? ??? ?name = n; ?? ??? ?salary = s; ?? ??? ?hireDay = LocalDate.of(year, mouth, day); ?? ?} ?? ?public String getName()//打印名字 ?? ?{ ?? ??? ?return name; ?? ?} ?? ?public double getSalary()//打印薪水 ?? ?{ ?? ??? ?return salary; ?? ?} ?? ?public LocalDate getHireDay()//工作时期 ?? ?{ ?? ??? ?return hireDay; ?? ?} ?? ?public void raiseSalary(double byPercent) ?? ?{ ?? ??? ?double raise = salary*byPercent/100; ?? ??? ?salary += raise; ?? ?} }
|