这一题java编程题怎么做啊,有点急

2024-11-10 12:25:24
推荐回答(2个)
回答(1):

代码如下,
****云客宝典技术团队****
答案可以解决您的需求,请将答案设置为采纳,如有不解,可以留言
package com.domax.org.abs;
public abstract class Animal {
protected String animalName;

public abstract void howl();
}

public class Cat extends Animal
{
public Cat(String animalName) {
super();
this.animalName = animalName;
}
public void howl() {
System.out.println(this.animalName + "正在喵喵");
}
}

public class Dog extends Animal {

public Dog(String animalName) {
super();
this.animalName = animalName;
}

@Override
public void howl() {
// TODO Auto-generated method stub
System.out.println(this.animalName +"正在旺旺");
}
}
package com.domax.org.abs;

public class Test {

public static void main(String[] args) {

Cat cat = new Cat("小猫");
Dog dog = new Dog("小狗");
cat.howl();
dog.howl();
}
}

回答(2):

public class Employee {

private String id;
private String name;
private double salary;
private int holiday;

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 double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public int getHoliday() {
return holiday;
}

public void setHoliday(int holiday) {
this.holiday = holiday;
}

/**
* 普通职员的工资计算方法
* @return
*/
public double salaryCut(){
double factSalaryCut=0.0d;
if (holiday<=5){
factSalaryCut=salary*(1-0.75);
}else{
factSalaryCut=salary*(1-0.5);
}
return factSalaryCut;
}
}
public class Manager extends Employee {
private static int medicalExpenses = 500;

public double salaryCompute4Manager(){
double firstPart = super.salaryCut();
double secondPart = getSalary()+(getSalary()*0.2)+(getSalary()*0.05)+medicalExpenses;
return secondPart-firstPart;
}
}

public class Director extends Employee {
private static int medicalExpenses = 200;
public double salaryCompute4Director(){
double firstPart = super.salaryCut();
double secondPart = getSalary()+(getSalary()*0.4)+(getSalary()*0.3)+medicalExpenses;
return secondPart-firstPart;
}
}

public class SalaryComputerMain {
public static void main(String[] args) {
Employee emp1 = new Employee();
emp1.setId("E01");
emp1.setName("王大毛");
emp1.setSalary(3000);
emp1.setHoliday(4);
System.out.println("员工:"+emp1.getName()+"的实发工资为62616964757a686964616fe58685e5aeb931333433623165:"+(emp1.getSalary()-emp1.salaryCut()));
Manager manager = new Manager();
manager.setId("E02");
manager.setName("王福林");
manager.setSalary(8000);
manager.setHoliday(5);
System.out.println("员工:"+manager.getName()+"的实发工资为:"+(manager.salaryCompute4Manager()));
Director director = new Director();
director.setId("E03");
director.setName("王健林");
director.setSalary(12000);
director.setHoliday(6);
System.out.println("员工:"+director.getName()+"的实发工资为:"+(director.salaryCompute4Director()));

}
}