JAVA 首先定义一个雇员类EMP,类的属性包括雇员编号ID,雇员名Name,年龄Age,性别Sex和专业Major,
代码刚写的还热乎,展开粘到环境里直接跑就行,注意换行
public class ForZhiDao {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
EMP emp = new EMP("5", "23", "王强", "男", "计算机网络专业");
PrintEMP(emp);
}
public static void PrintEMP(EMP emp) {
System.out.println(emp.toString());
}
static class EMP {
String ID;
String Name;
String Age;
String Sex;
String Major;
public EMP(String iD, String name, String age, String sex, String major) {
super();
ID = iD;
Name = name;
Age = age;
Sex = sex;
Major = major;
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getAge() {
return Age;
}
public void setAge(String age) {
Age = age;
}
public String getSex() {
return Sex;
}
public void setSex(String sex) {
Sex = sex;
}
public String getMajor() {
return Major;
}
public void setMajor(String major) {
Major = major;
}
public String toString() {
return "ID:" + ID + ",Name:" + Name + ",Age:" + Age + ",Sex:" + Sex + ",Major:" + Major;
}
}
}
private String ID;
private String Name;
private String Age;
private String Sex;
private String Major;
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getAge() {
return Age;
}
public void setAge(String age) {
Age = age;
}
public String getSex() {
return Sex;
}
public void setSex(String sex) {
Sex = sex;
}
public String getMajor() {
return Major;
}
public void setMajor(String major) {
Major = major;
}
public EMP(String ID, String name, String age, String sex, String major) {
this.ID = ID;
Name = name;
Age = age;
Sex = sex;
Major = major;
}
public void PrintEMP(){
System.out.println("ID:" + getID());
System.out.println("Name:" + getName());
System.out.println("Age:" + getAge());
System.out.println("Sex:" + getSex());
System.out.println("Major:" + getMajor());
}
public static void main(String[] args) {
EMP emp = new EMP("5","王强","23","男","计算机网络专业");
emp.PrintEMP();
}
}