| - demand explanation
| - realization of ideas
1, create a class of employees, used as an array of objects, store employee information
2. Create a collection set inside the test class, add an array of objects in the collection inside
3, required input information, based on the information input by the user through the entire collection set, matched to the outputs
. | - Content Code
1 // Create employee class, for creating an array of objects, to facilitate data storage 2 public class Staff { . 3 Private String name; . 4 Private String ename; . 5 Private String ID; . 6 Private String Gender; . 7 . 8 public Staff () { . 9 } 10 . 11 public Staff (String name, String ename, ID String, String Gender) { 12 is the this .name = name; 13 is the this .ename = ename; 14 the this .id = ID; 15 this.gender = gender; 16 } 17 18 public String getName() { 19 return name; 20 } 21 22 public void setName(String name) { 23 this.name = name; 24 } 25 26 public String getEname() { 27 return ename; 28 } 29 30 public void setEname(String ename) { 31 this.ename = ename; 32 } 33 34 public String getId() { 35 return id; 36 } 37 38 public void setId(String id) { 39 this.id = id; 40 } 41 42 public String getGender() { 43 return gender; 44 } 45 46 public void setGender(String gender) { 47 this.gender = gender; 48 } 49 }
1 public class StaffTest { 2 public static void main (String [] args) { 3 // initialize personnel information, company personnel entry list 4 Staff STAFF1 = new new Staff ( "Li", "Jack", "M8985 ", " M " ); 5 Staff staff2 = new new Staff (" Wang Wei "," Tom "," K8975 "," male " ); 6 7 // create a collection of elements in the set which added 8 the Set the SET = new new HashSet (); 9 the SET .add (STAFF1); 10 set.add (staff2); . 11 12 is // require user input information 13 Scanner = Scanner new new Scanner (System.in); 14 System.out.println ( "Please enter the person you want to query the English name" ); 15 String GUESS = Scanner.next (); 16 17 18 // based on user input information corresponding to the query name and sex workers in Chinese . 19 for (Object O: SET) { 20 is // the object type coerced to staff type 21 is staff = staff (staff) O; 22 is // Analyzing, English name entered by the user to match the name of personnel information which, if it matches the output on 23 IF (staff.getEname (). the equals (GUESS)) { 24- // will staff.getName forced into String 25 String name =(String) staff.getName (); 26 is // the staff.getGender forced into String 27 String Gender = (String) staff.getGender (); 28 // output 29 System.out.println (+ GUESS "corresponding participant's name is: "+ name +" gender: "+ gender); 30 // matching place, exit the traverse 31 is BREAK ; 32 } 33 is } 34 is } 35 }
| - operating results