第一题看的脑壳疼,但是和第二题的意思差不多,我帮你做了第二题
public class List {public static void main(String[] args) {
Employee e1 = new Employee("张强","2010/09/01",6890)
e1.show("普通")
System.out.println("年纳税:"+e1.tax())
Manager m1 = new Manager("朱慧","2003/07/06",18530,38000)
m1.show("管理")
System.out.println("年纳税:"+m1.tax())
}
}
//下面是补全的代码
class Employee{
String name,date
double salary,bonus
Employee(String name,String date,double salary){
this.name = name
this.date = date
this.salary = salary
}
public void show(String str){
System.out.println("岗位:"+str)
System.out.println("姓名:"+name+",入职时间:"+date+",月薪:"+salary)
}
public double tax(){
if(salary <= 0){
throw new RuntimeException("工资不允许小于等于0")
}
else if(salary>3000 && salary<=5000){
salary = salary*0.05*12 //纳税这里我也不知道他们具体是怎么个算法,反正意思差不多,套进去就行了
}
else if(salary>5000 && salary<=10000){
salary = salary*0.1*12
}
else if(salary>10000 && salary<=15000){
salary = salary*0.15*12
}
else if(salary>15000){
salary = salary*0.2*12
}
return salary+(bonus*0.2)
}
}
class Manager extends Employee{
Manager(String name,String date,double salary,double bonus){
super(name,date,salary)
super.bonus = bonus
}
public void show(String str){
System.out.println("岗位:"+str)
System.out.println("姓名:"+name+",入职时间:"+date+",月薪:"+salary+",奖金:"+bonus)
}
}
代码如下
class Box{
private int width
private int length
private int height
public Box(int width,int length,int height){
this.width = width
this.length = length
this.height = height
}
public void showBox(){
System.out.println("盒子的width、length、height分别为"+width+","+length+","+height)
}
}
如果有帮助到你,请点击采纳
按照题目要求编写的圆,圆锥和测试类的Java程序如下
Test.java文件内容如下
class Circle{
private double r
private String color
public Circle(double r){
this.r=r
}
public double area(){
return Math.PI*r*r
}
public double perimeter(){
return Math.PI*2*r
}
public double getR(){
return this.r
}
public void setR(double r){
this.r=r
}
public String getColor(){
return this.color
}
public void setColor(String color){
this.color=color
}
public String toString(){
return "圆的半径为"+r+",颜色为"+color
}
}
class Cone{
private Circle c
private double h
private String color
public Cone(Circle c,double h){
this.c=c
this.h=h
}
public double volume(){
return 1.0/3*c.area()*h
}
public Circle getCircle(){
return this.c
}
public void setCircle(Circle c){
this.c=c
}
public double getH(){
return this.h
}
public void setH(double h){
this.h=h
}
public String getColor(){
return this.color
}
public void setColor(String color){
this.color=color
}
public String toString(){
return "圆锥的底面积为"+c.area()+",高为"+h+",颜色为"+color
}
}
public class Test{
public static void main(String[] args){
Circle circle1=new Circle(2.5)
circle1.setColor("红色")
System.out.println(circle1.toString())
System.out.println("圆的面积为"+circle1.area())
System.out.println("圆的周长为"+circle1.perimeter())
Cone circlar1=new Cone(circle1,2.7)
circlar1.setColor("蓝色")
System.out.println(circlar1.toString())
System.out.println("圆锥的体积为"+circlar1.volume())
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)