
正文
Java代码创建营业员类 java程序怎么创建
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用Java语言定义一个员工类Employee
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;
}
}
相关问答
Q1: 用java编写员工类Employee
public class Employee {
private int id;
private byte sex;
private String name;
private String duty;
private float salary;
private int holidays;
public Employee(int id,byte sex,String name,String duty, float salary,int holidays){
this.id = id;
this.sex = sex;
this.name = name;
this.duty = duty;
this.salary = salary;
this.holidays = holidays;
}
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public int getHolidays() {
return holidays;
}
public void setHolidays(int holidays) {
this.holidays = holidays;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public byte getSex() {
return sex;
}
public void setSex(byte sex) {
this.sex = sex;
}
/**
* display(),无返回值,该方法能打印员工的姓名、性别以及职务
* @param employee
*/
public void display(Employee employee){
System.out.println("员工姓名为: " + employee.getName());
if(employee.getSex()==1){
System.out.println("员工性别为: 男 ");
}else if(employee.getSex()==2){
System.out.println("员工性别为:女 ");
}
System.out.println("员工职务为: " + employee.getDuty());
}
/**
* getDecMoney(int day) 返回值是int型。
* 如果请假天数=3,则扣款为30×请假天数;
* 如果请假天数超过3天,则扣款为50×请假天数。
* @param day
* @return
*/
public int getDecMoney(int day){
int deduction = 0; //扣除的工资
if(day = 3){
deduction = 30*day;
}else if(day 3){
deduction = 50*day;
}
return deduction;
}
public static void main(String[] args){
//创建一个员工类的对象
Employee employee = new Employee(123456789,(byte) 1,"陈冠希","生产帽子的(绿色)",(float) 500.8,5);
employee.display(employee); //调用display()
int deduction = employee.getDecMoney(employee.getHolidays());//调用getDecMoney()
System.out.println("该员工因请假扣除工资" + deduction + "元");
}
}
Q2: java创建两个类公司类和职员类自定义五个员工
public class Test{
//此示例代码Java代码创建营业员类我只添加Java代码创建营业员类了两个员工、两个部门Java代码创建营业员类,仅供参考
public static void main(String[] args) {
Dept d1 = new Dept();
d1.setDeptId(1);
d1.setDeptName("财务部");
Dept d2 = new Dept();
d2.setDeptId(2);
d2.setDeptName("技术部");
Emp e1 = new Emp();
e1.setEmpId(1);
e1.setEmpName("张三");
Emp e2 = new Emp();
e2.setEmpId(2);
e2.setEmpName("李四");
e1.setDept(d1);
e2.setDept(d2);
}
}
class Dept{
private Integer deptId;
private String deptName;
public void setDeptId(Integer deptId){
this.deptId = deptId;
}
public Integer getDeptId(){
return deptId;
}
public void setDeptName(String deptName){
this.deptName = deptName;
}
public String getDeptName(){
return deptName;
}
}
class Emp{
private Integer empId;
private String empName;
private Dept dept;
public void setEmpId(Integer empId){
this.empId = empId;
}
public Integer getEmpId(){
return empId;
}
public void setEmpName(String empName){
this.empName = empName;
}
public String getEmpName(){
return empName;
}
public void setDept(Dept dept){
this.dept = dept;
}
public Dept getDept(){
return dept;
}
}
Java代码创建营业员类的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java程序怎么创建、Java代码创建营业员类的信息别忘了在本站进行查找喔。





