用Java语言定义一个员工类Employee
(1)员工类Employee属性有:id:String型,代表员工ID号name:String型,代表姓名age:int型,代表年龄sex:boolen型,代表性别(其中...
(1) 员工类Employee属性有:
id : String型,代表员工ID号
name : String型,代表姓名
age : int型,代表年龄
sex : boolen型,代表性别(其中:true表示男,false表示女)
phone : String型,代表联系电话
salary: float型,代表员工薪水
(2) 员工类Employee的方法有:
Employee(String sId, String sName, int sAge, boolean sSex, String sPhone, float sSalary ):有参数构造方法,分别初始化ID号、姓名、年龄、性别、联系电话和薪水属性。
public String toString() : 以 “姓名:联系电话”的形式作为方法的返回值。
所有成员变量的get和set方法。 展开
id : String型,代表员工ID号
name : String型,代表姓名
age : int型,代表年龄
sex : boolen型,代表性别(其中:true表示男,false表示女)
phone : String型,代表联系电话
salary: float型,代表员工薪水
(2) 员工类Employee的方法有:
Employee(String sId, String sName, int sAge, boolean sSex, String sPhone, float sSalary ):有参数构造方法,分别初始化ID号、姓名、年龄、性别、联系电话和薪水属性。
public String toString() : 以 “姓名:联系电话”的形式作为方法的返回值。
所有成员变量的get和set方法。 展开
5个回答
展开全部
public class Employee {
private String id; // 员工ID号
private String name; // 姓名
private int age; // 年龄
private boolean sex; // 性别(其中:true表示男,false表示女)
private String phone; // 联系电话
private float salary; // 薪水
Employee(String sId, String sName, int sAge, boolean sSex, String sPhone,
float sSalary) {
this.id = sId;
this.name = sName;
this.age = sAge;
this.sex = sSex;
this.phone = sPhone;
this.salary = sSalary;
}
public String toString() {
return "员工ID号:" + this.id + "\n员工姓名:" + this.name + "\n员工年龄:"
+ this.age + "\n员工性别:" + (this.sex == true ? "男" : "女")
+ "\n联系电话:" + this.phone + "\n薪水:" + this.salary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
}
private String id; // 员工ID号
private String name; // 姓名
private int age; // 年龄
private boolean sex; // 性别(其中:true表示男,false表示女)
private String phone; // 联系电话
private float salary; // 薪水
Employee(String sId, String sName, int sAge, boolean sSex, String sPhone,
float sSalary) {
this.id = sId;
this.name = sName;
this.age = sAge;
this.sex = sSex;
this.phone = sPhone;
this.salary = sSalary;
}
public String toString() {
return "员工ID号:" + this.id + "\n员工姓名:" + this.name + "\n员工年龄:"
+ this.age + "\n员工性别:" + (this.sex == true ? "男" : "女")
+ "\n联系电话:" + this.phone + "\n薪水:" + this.salary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package com.aaron.help;
public class Employee {
private String id;
private String name;
private int age;
private boolean sex;
private String phone;
private float salary;
public Employee() {
}
public Employee(String sId, String sName, int sAge, boolean sSex,
String sPhone, float sSalary) {
this.id = sId;
this.name = sName;
this.age = sAge;
this.sex = sSex;
this.phone = sPhone;
this.salary = sSalary;
}
public String toString() {
return (name + ": " + phone);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
}
public class Employee {
private String id;
private String name;
private int age;
private boolean sex;
private String phone;
private float salary;
public Employee() {
}
public Employee(String sId, String sName, int sAge, boolean sSex,
String sPhone, float sSalary) {
this.id = sId;
this.name = sName;
this.age = sAge;
this.sex = sSex;
this.phone = sPhone;
this.salary = sSalary;
}
public String toString() {
return (name + ": " + phone);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那个...
咱性别用Gender行不?
Sex太露骨了吧...
`
哥们,不是我不答你..
你连这都问,是不是没学过Java?
咱性别用Gender行不?
Sex太露骨了吧...
`
哥们,不是我不答你..
你连这都问,是不是没学过Java?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个问题 太.....
定义完变量 可以自动生成 get set 方法
定义完变量 可以自动生成 get set 方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
推荐你用Eclipse这些get set方法都直接可以生成
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询