java公司支出薪水代码 java计算员工工资编程题( 二 )


BufferedReader personType = new BufferedReader(new InputStreamReader(
System.in));
String type = null;
int hour = 0;
try {
type = personType.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (type.matches("[1-4]{1}")) {
switch (Integer.valueOf(type)) {
case 1:
hour = getHour();
if(hour == 0){return;}
Person p1 = new Assistant();
double pay1 = p1.countPay(hour);
System.out.println("助教工作" + hour + "课时的工资为:" + pay1);
break;
case 2:
hour = getHour();
if(hour == 0){return;}
Person p2 = new Instructor();
double pay2 = p2.countPay(hour);
System.out.println("讲师工作" + hour + "课时的工资为:" + pay2);
break;
case 3:
hour = getHour();
if(hour == 0){return;}
Person p3 = new AssistantProfesson();
double pay3 = p3.countPay(hour);
System.out.println("副教授工作" + hour + "课时的工资为:" + pay3);
break;
case 4:
hour = getHour();
if(hour == 0){return;}
Person p4 = new Professor();
double pay4 = p4.countPay(hour);
System.out.println("教授工作" + hour + "课时的工资为:" + pay4);
break;
}
} else {
System.out.println("输入数据错误java公司支出薪水代码!程序提前推出java公司支出薪水代码!");
return;
}
}
public static int getHour() {
System.out.print("请输入工作时间:");
BufferedReader hours = new BufferedReader(new InputStreamReader(
System.in));
String strHour = null;
int hour = 0;
try {
strHour = hours.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (strHour.matches("^[0-9]+?")) {
hour = Integer.parseInt(strHour);
} else {
System.out.println("输入参数不正确!程序提前推出!");
}
return hour;
}
}
请求大神帮我解答这道java编程题(填写代码)此题的Employee类设计有缺陷,缺少员工薪水的属性 。根据题意只能写出下面的程序:
abstract class Employee {
public abstract double earnings();
}
class YearWorker extends Employee {
@Override
public double earnings() {
return 0;
}
}
class MonthWorker extends Employee {
@Override
public double earnings() {
return 0;
}
}
class WeekWorker extends Employee {
@Override
public double earnings() {
return 0;
}
}
class Company {
Employee[] employee;
double salaries = 0;
Company(Employee[] employee) {
this.employee = employee;
}
public double salariesPay() {
salaries = 0;
//计算salaries
for(int i=0; iemployee.length; i++) {
salaries += employee[i].earnings();
}
return salaries;
}
}
public class HardWork {
public static void main(String[] args) {
Employee[] employee = new Employee[20];
for(int i=0; iemployee.length; i++) {
if(i % 3 == 0) {
employee[i] = new YearWorker();
}
else if(i % 3 == 1) {
employee[i] = new MonthWorker();
}
else if(i % 3 == 2) {
employee[i] = new WeekWorker();
}
}
Company company = new Company(employee);
System.out.println("公司年工资总额:" + company.salariesPay());
}
}
运行结果:
公司年工资总额:0.0
【java公司支出薪水代码 java计算员工工资编程题】关于java公司支出薪水代码和java计算员工工资编程题的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

推荐阅读