出题人 刘凤良
单位 天津仁爱学院
有一家软件外包公司,可以外派开发人员,该软件公司有两个角色,普通开发人员和项目管理,它们有共同的属性"姓名","年龄" 普通开发人员有自己特有的属性"工作经验",他的工作内容是"开发项目",项目经理有自己特有的属性“项目管理经验”,他的工作内容是项目管理,对外的报价是普通开发人员每天 500 元,超过 60 天每天 400 元,项目经理每天 800 元,超过 60 天每天 600 元,有一家银行需要1名项目经理,2 名开发人员,现场开发 90 天,计算银行需要付给软件公司的总金额。
函数接口定义:
void work(); //工作内容
double calcMoney(int days); //计算开发 days 天所需金额
裁判测试程序样例:
import java.util.Scanner; public class Main { public static void main(String[] args) { Employee[] employees = new Employee[3]; Developer d1 = new Developer("小王", 23); Developer d2 = new Developer("小李", 22); Manager manager = new Manager("老张", 32); employees[0] = d1; employees[1] = d2; employees[2] = manager; //输入开发天数 Scanner input = new Scanner(System.in); int days = input.nextInt(); //计算所需金额 double totalMoney = 0; for (Employee employee : employees) { totalMoney += employee.calcMoney(days); } System.out.println("开发:" + days + "天,总共需要支付:" + totalMoney + "元!"); } } /* 请在这里填写答案 */
输入样例:
90
输出样例:
开发:90天,总共需要支付:126000.0元!
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
答题:张鹏宇 内蒙古师范大学20信班
我的代码:
abstract class Employee{
String name;
int age;
Employee(String name,int age){
this.name=name;
this.age=age;
}
abstract void work();
abstract double calcMoney(int days);
}
class Developer extends Employee{
int workexperience;
Developer(String name,int age){
super(name,age);
}
void work() {
System.out.println("开发项目");
}
double calcMoney(int days) {
if(days<60) {
return days*500;
}else {
return days*400;
}
}
}
class Manager extends Employee{
int manageexperience;
Manager(String name,int age){
super(name,age);
}
void work() {
System.out.println("项目管理");
}
double calcMoney(int days) {
if(days<60) {
return days*800;
}else {
return days*600;
}
}
}