com.wana Package; Import java.time.LocalDate; / ** * @author JackZhao * @Create 2020-03-24 PM 12:47 * / public class EmployeeTest { public static void main (String [] args) { the Employee [ ] = new new Staff the employee [. 3]; // build employee array Staff [0] = the employee new new ( "Carl Cracker", 75000, 1987, 12 is, 15); Staff [. 1] = new new the employee ( "Harry Hacker", 50000 , 1989, 10,. 1); Staff [2] = the Employee new new ( "Tony Tester", 40000, 1990,. 3, 15); // fill an array of objects for (the Employee E: Staff) e.raiseSalary (. 5) ; // py like most of the for statement is really easy to use, processing Employee array staff. for (Employee e: staff) System.out.println ( "name =" e.getName + () + ", the salary =" e.getSalary + () + ", hireDay =" + e.getHireDay ()); } } class the Employee { Private String name ; Private Double the salary; Private the LocalDate hireDay; public Employee (n-String, Double S, int year, month the int, int Day) // (builder) processing array Employee object information filled { name = n-; // here instance fields are variable rather than a local variable, for example: String name local variable is the salary = S; hireDay = LocalDate.of (year, month the, Day); } public String getName () { return name; } // returns the name Methods Double getSalary public () { return the salary; } // return salary method public the LocalDate getHireDay () { return hireDay; } // return time of an entry public void raiseSalary (double byPercent) // salary growth method { Double The raise = * byPercent the salary / 100; the salary the raise + =; } } / * original can be used: an array 1 constructed in accordance with one class;. 2. a method of processing information based reuse filled array of objects. * /
Note: Use instance variables and local variables;
constructor class with the same name, so that when the object is constructed, the constructor will start, for instance field is initialized (information processing)