三九宝宝网宝宝成长经典故事

计算机java编程题

02月12日 编辑 39baobao.com

根据题号,代码如下:

1、 public class Emp { private String uName; private double money; static final double empOp=0.012;//应缴个人所得税 public String getuName() { return uName; } public void setuName(String uName) { this.uName = uName; } public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } public Emp() {} public Emp(String uName, double money) { this.uName=uName; this.money=money; } public String show() { return "员工姓名:"+getuName()+"\n应缴个人所得税:"+getMoney()*empOp; } public static void main(String[] args) { Emp emp = new Emp("张三",6000); System.out.println(emp.show()); }}

2、 public class Student { private String name; private int age; private String degree; 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 String getDegree() { return degree; } public void setDegree(String degree) { this.degree = degree; } public String show() { return "姓名:"+getName()+"\n年龄:"+getAge()+"\n学位:"+getDegree(); } public static void main(String[] args) { Graduate g = new Graduate(); g.setAge(22); g.setName("张三"); g.setDegree("研究生"); g.setDirection("计算机科学与技术"); System.out.println(g.show()); }}class Undergraduate extends Student{ private String specialty; public String getSpecialty() { return specialty; } public void setSpecialty(String specialty) { this.specialty = specialty; } public String show() { return "姓名:"+getName()+"\n年龄:"+getAge()+"\n学位:"+getDegree()+"\n专业:"+getSpecialty(); }}class Graduate extends Student{ private String direction; public String getDirection() { return direction; } public void setDirection(String direction) { this.direction = direction; } public String show() { return "姓名:"+getName()+"\n年龄:"+getAge()+"\n学位:"+getDegree()+"\n研究方向:"+getDirection(); } } 满意请采纳,谢谢!

推荐阅读
图文推荐