第一题看的脑壳疼,但是和第二题的意思差不多,我帮你做了第二题
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 Car extends Vehicle{super(speed,kind,color)
private int passenger
public void Car(int speed,String kind,String color,int passenger){
this.speed=speed
this.kind=kind
this.color=color
this.passenger=passenger
}
public void setCar(int speed,String kind,String color){
this.speed=speed
this.kind=kind
this.color=color
}
public void setPassenger(int passenger){
this.passenger=passenger
}
public int getSpeed(){
return speed
}
public String getKind(){
return kind
}
public String getColor(){
return color
}
public int getPassenger(){
return passenger
}
public String toString(){
return "速度:"+speed+"类型:"+kind+"颜色:"+color+"人数"+passenger
}
}
public class test{
public static void main(String[] args){
Vehicle c=new Car()
c.setCar(100,"小车","red")
c.setPassenger(5)
System.out.println(c.toString())
}
}
打了半天.不知道有没有错..你调调看吧.呵呵..都不太记得了.
//人接口public interface Human {
void speak()
}
//教师类
public class Teacher implements Human {
public void speak() {
System.out.println("speak")
}
public void teach() {
System.out.println("teach")
}
}
//学生类
public class Student implements Human {
public void speak() {
System.out.println("speak")
}
public void learn() {
System.out.println("learn")
}
}
//测试类
class HumanTest {
@Test
void test() {
Teacher teacher=new Teacher()
Student stu=new Student()
teacher.teach()
teacher.speak()
stu.learn()
stu.speak()
}
}
运行结果:
teach
speak
learn
speak
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)