麻烦各位java程序大神,帮助我一下,给我下面一道java题的代码呗?我是真不会。
按以下要求完成类的设计与对象创建:(1)定义一个职工类(Employee),定义2个属性并对其封装,属性包括职工编号(identifier)、职工姓名(name);定义一...
按以下要求完成类的设计与对象创建:
(1)定义一个职工类(Employee),定义2个属性并对其封装,属性包括职工编号(identifier)、职工姓名(name);定义一个2个参数的构造方法,用于对职工编号、职工姓名两个属性的初始化;定义一个成员方法work(),用于描述员工工作情况(如:输出“工作时间:周一至周五,朝九晚五”);定义一个成员方法showInfo()用于输出职工基本信息。
(2)通过继承Employee类定义一个经理类(Manager),定义一个属性工作部门(department),并封装;改写父类的showInfo()方法,在输出职工编号、职工姓名的基础上,输出工作部门;
(3)通过继承Employee类定义一个董事长类(Chairman),改写父类的work方法,使其输出“董事长主持召开股东大会”。
(4)编写测试类(类名以姓名拼音加作业序号命名),在测试类中分别创建3个类的对象,对所有属性进行初始化或赋值,分别调用自身定义的方法和从父类继承来来的方法。 展开
(1)定义一个职工类(Employee),定义2个属性并对其封装,属性包括职工编号(identifier)、职工姓名(name);定义一个2个参数的构造方法,用于对职工编号、职工姓名两个属性的初始化;定义一个成员方法work(),用于描述员工工作情况(如:输出“工作时间:周一至周五,朝九晚五”);定义一个成员方法showInfo()用于输出职工基本信息。
(2)通过继承Employee类定义一个经理类(Manager),定义一个属性工作部门(department),并封装;改写父类的showInfo()方法,在输出职工编号、职工姓名的基础上,输出工作部门;
(3)通过继承Employee类定义一个董事长类(Chairman),改写父类的work方法,使其输出“董事长主持召开股东大会”。
(4)编写测试类(类名以姓名拼音加作业序号命名),在测试类中分别创建3个类的对象,对所有属性进行初始化或赋值,分别调用自身定义的方法和从父类继承来来的方法。 展开
2个回答
2020-03-19
展开全部
/**
* 职工类
*/
public class Employee {
private String identifier;//职工编号
private String name;//职工姓名
public Employee() {
}
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName());
}
}
/**
* 经理类
*/
public class Manager extends Employee{
private String department;//工作部门
public Manager(String identifier, String name) {
super(identifier, name);
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName()+",负责的工作部门:"+getDepartment());
}
}
/**
* 董事长类
*/
public class Chairman extends Employee{
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}
/**
* 测试类:类名DemoTest03
*/
public class DemoTest03 {
public static void main(String[] args) {
Employee e = new Employee("07","益达");
Manager m = new Manager("01","小黑");
m.setDepartment("爱情公寓");
Chairman c = new Chairman();
e.showInfo();
e.work();
m.showInfo();
c.work();
}
}
* 职工类
*/
public class Employee {
private String identifier;//职工编号
private String name;//职工姓名
public Employee() {
}
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName());
}
}
/**
* 经理类
*/
public class Manager extends Employee{
private String department;//工作部门
public Manager(String identifier, String name) {
super(identifier, name);
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName()+",负责的工作部门:"+getDepartment());
}
}
/**
* 董事长类
*/
public class Chairman extends Employee{
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}
/**
* 测试类:类名DemoTest03
*/
public class DemoTest03 {
public static void main(String[] args) {
Employee e = new Employee("07","益达");
Manager m = new Manager("01","小黑");
m.setDepartment("爱情公寓");
Chairman c = new Chairman();
e.showInfo();
e.work();
m.showInfo();
c.work();
}
}
2020-03-19
展开全部
public class Demo {
public static void main(String[] args) {
Employee employee = new Employee("003", "张三");
Manager manager = new Manager("002", "李四", "财务部");
Chairman chairman = new Chairman("001", "王麻子");
employee.showInfo();
employee.work();
manager.showInfo();
manager.work();
chairman.showInfo();
chairman.work();
}
}
class Employee {
private String identifier;
private String name;
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("职工编号" + this.identifier + ", 职工姓名: " + this.name);
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Manager extends Employee {
private String department;
public Manager(String identifier, String name, String department) {
super(identifier, name);
this.department = department;
}
@Override
public void showInfo() {
System.out.println("职工编号" + this.getIdentifier() + ", 职工姓名: " + this.getName() + ", 工作部门: " + this.department);
}
public String getDepartment() {
return department;
}
}
class Chairman extends Employee {
public Chairman(String identifier, String name) {
super(identifier, name);
}
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}
public static void main(String[] args) {
Employee employee = new Employee("003", "张三");
Manager manager = new Manager("002", "李四", "财务部");
Chairman chairman = new Chairman("001", "王麻子");
employee.showInfo();
employee.work();
manager.showInfo();
manager.work();
chairman.showInfo();
chairman.work();
}
}
class Employee {
private String identifier;
private String name;
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("职工编号" + this.identifier + ", 职工姓名: " + this.name);
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Manager extends Employee {
private String department;
public Manager(String identifier, String name, String department) {
super(identifier, name);
this.department = department;
}
@Override
public void showInfo() {
System.out.println("职工编号" + this.getIdentifier() + ", 职工姓名: " + this.getName() + ", 工作部门: " + this.department);
}
public String getDepartment() {
return department;
}
}
class Chairman extends Employee {
public Chairman(String identifier, String name) {
super(identifier, name);
}
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |