package 第3章;
import java.time.*;
public class 第3章a
{
public static void main(String[] args)
{
Employee[] men=new Employee[3];
men[0]=new Employee("hello",20000,2001,1,2);
men[1]=new Employee("well",30000,2002,2,3);
men[2]=new Employee("good",10000,2003,3,4);
for(Employee a: men)
{
a.ChangeSalary(5);
}
for(Employee b:men)
{
System.out.println("name= "+b.getName()+",salary= "+b.getSalary()+",hireTime= "+b.getHireTime());
}
}
}
class Employee
{
private String name;
private double salary;
private LocalDate hireTime;
public Employee(String n,double s ,int year,int month,int day)
{
name=n;
salary=s;
hireTime=LocalDate.of(year, month, day);
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public LocalDate getHireTime()
{
return hireTime;
}
public void ChangeSalary(double number)
{
double Changing=salary*number/100;
salary+=Changing;
}
}
run:
name= hello,salary= 21000.0,hireTime= 2001-01-02
name= well,salary= 31500.0,hireTime= 2002-02-03
name= good,salary= 10500.0,hireTime= 2003-03-04
成功构建 (总时间: 0 秒)
Again
package 第3章;
import java.time.*;
public class 第3章a
{
public static void main(String[] args)
{
Employee[] man=new Employee[2];
man[0]=new Employee("hello",200000,2003,2,8);
man[1]=new Employee("well",300000,2005,1,29);
for(Employee a:man)
System.out.println("name is "+a.getName()+", salary is "+a.getSalary()+", hireTime is "+a.getHireTime());
for(Employee b:man)
{
b.increaseSalary(5);
}
for(Employee c:man)
System.out.println(c.getSalary());
}
}
class Employee
{
private double salary;
private String name;
private LocalDate hireTime;
public Employee(String n,double s,int year,int month,int day)
{
name=n;
salary=s;
hireTime=LocalDate.of(year, month, day);
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public LocalDate getHireTime()
{
return hireTime;
}
public void increaseSalary(double number)
{
double increase=salary*number/100;
salary+=increase;
}
}
run:
name is hello, salary is 200000.0, hireTime is 2003-02-08
name is well, salary is 300000.0, hireTime is 2005-01-29
210000.0
315000.0
成功构建 (总时间: 0 秒)