package mianxiangduixiang;
public class Employee15 {
//属性
private String name;
private char gender;
private int age;
private String phoneNumber;
//方法
public void setName(String n){
name=n;
}
public String getName(){
return name;
}
public void setGender(char g){
gender=g;
}
public char getGender(){
return gender;
}
public void setAge(int a){
age=a;
}
public int getAge(){
return age;
}
public void setPhoneNumber(String p){
phoneNumber=p;
}
public String getPhoneNumber(){
return phoneNumber;
}
//输出遍历
public String getInfo(){
return name+"\t"+gender+"\t"+age+"\t"+phoneNumber;
}
}
package mianxiangduixiang;
import java.util.Scanner;
public class EmployeeTest15 {
public static void main(String[] args) {
Employee15[]emps=new Employee15[2];
Scanner scan=new Scanner(System.in);
for (int i=0;i<emps.length;i++){
emps[i]=new Employee15();
System.out.println("----------添加第"+(i+1)+"个员工----------");
System.out.println("姓名:");
String name=scan.next();
System.out.println("性别:");
char gender=scan.next().charAt(0);
System.out.println("年龄:");
int age=scan.nextInt();
System.out.println("电话:");
String phoneNumber=scan.next();
emps[i].setName(name);
emps[i].setGender(gender);
emps[i].setAge(age);
emps[i].setPhoneNumber(phoneNumber);
}
System.out.println("----------员工列表----------");
System.out.println("姓名\t性别\t年龄\t电话");
for (int i=0;i<emps.length;i++){
System.out.println((i+1)+"\t"+emps[i].getInfo());
}
System.out.println("----------员工列表完成----------");
}
}