老师留下的第五次作业:
1.Employee:这是所有员工总的父类,
属性:员工的姓名和生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
SalariedEmployee:Employee子类,拿固定工资的员工。
属性:月薪
HourlyEmployee:Employee子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数
在测试类中,定义Employee的数组,长度为4(每种员工2名),统计并显示当月的工资情况。要求使用多态技术
2.定义一个接口Area,其中包含一个计算面积的方法calcArea(),然后设计MyCircle和MyRectangle两个类都实现这个接口中的方法calcArea(),分别计算圆和矩形的面积,最后写出测试以上类和方法的程序。
3.有三种交通工具飞机、轮船、汽车
它们有各自的行驶方式(水、路、空)
它们有各自的载人数量
它们有各自的行驶速度
只有轮船和汽车可以打开窗子
用继承、多态和接口(打开窗子)编码。
public class EmployeeTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Employee[] e = new Employee[4];
System.out.print("请输入查询月份:");
int month = sc.nextInt();
for(int i = 0;i<2;i++) {
System.out.print("请输入第" +(i + 1) + "员工的姓名和出生月份:");
e[i] = new SalariedEmployee(sc.next(),sc.nextInt(),sc.nextInt());
e[i].getSalary(month);
}
for(int i = 2;i<4;i++) {
System.out.print("请输入小时工的姓名和出生月份和工作时长:");
e[i] = new HourlyEmployee(sc.next(),sc.nextInt(),sc.nextInt());
e[i].getSalary(month);
}
for(int i = 0;i<4;i++)
e[i].print();
}
}
class Employee{
String n;
int month,m,prize;
Employee(String n,int m){
this.n = n;
this.m = m;
}
void print() {
// TODO Auto-generated method stub
}
void getSalary(int month){
this.month = month;
if(m == month)
prize = 100;
}
}
class SalariedEmployee extends Employee{
int s;
SalariedEmployee(String n,int m,int s) {
super(n, m);
// TODO Auto-generated constructor stub
this.s = s;
}
void print() {
System.out.println("正式工" + n + "当月工资为:" + (s + prize));
}
}
class HourlyEmployee extends Employee{
int h,s;
HourlyEmployee(String n,int m,int h) {
super(n, m);
// TODO Auto-generated constructor stub
this.h = h;
if(h < 160 && h > 0)
s = 10 * h;
else
s = 160 + (h - 160) * 15;
}
void print() {
System.out.println("小时工" + n + "当月工资为:" + (s + prize));
}
}
但凡上机前敲了这题,呜呜呜我也不会那么一塌糊涂呜呜呜
第三题主要就是熟练度的问题嘛,一般来说应该没问题的,吧