diff --git "a/19 \351\231\210\345\246\203/20230508.md" "b/19 \351\231\210\345\246\203/20230508.md" deleted file mode 100644 index 1b917bc918030f125b10be3634d67175a2609b34..0000000000000000000000000000000000000000 --- "a/19 \351\231\210\345\246\203/20230508.md" +++ /dev/null @@ -1,256 +0,0 @@ -### 2、员工 - -(1)声明一个父类Employee员工类型, - -- 有姓名属性,私有化,提供get/set方法 -- public double earning():代表实发工资,返回0.0 -- public String getInfo():显示姓名和实发工资 - -(2)声明MyDate类型 - -- 有int类型的年,月,日属性,私有化,提供get/set方法 -- 提供public String getInfo(),返回“xxxx年xx月xx日” - -(3)声明一个子类SalaryEmployee正式工,继承父类Employee - -- 增加属性,double类型的薪资,MyDate类型的出生日期,私有化,提供get/set方法 -- 重写方法,public double earning()返回实发工资, 实发工资 = 薪资 -- 重写方法,public String getInfo():显示姓名和实发工资、生日 - -(4)声明一个子类HourEmployee小时工,继承父类Employee - -- 有属性,double类型的工作小时数和每小时多少钱 -- 重写方法,public double earning()返回实发工资, 实发工资 = 每小时多少钱 * 小时数 -- 重写方法,public String getInfo():显示姓名和实发工资,时薪,工作小时数 - -(5)声明一个子类Manager经理,继承SalaryEmployee - -- 增加属性:奖金比例,私有化,提供get/set方法 -- 重写方法,public double earning()返回实发工资, 实发工资 = 薪资 *(1+奖金比例) -- 重写方法,public String getInfo():显示姓名和实发工资,生日,奖金比例 - -(6)声明一个员工数组,存储各种员工,你现在是人事,遍历查看每个人的详细信息,并统计实发工资总额,通知财务准备资金。 - -(7)从键盘输入当期月份值,如果他是正式工(包括SalaryEmployee和Manager),并且是本月生日的,通知领取生日礼物。 - - - -~~~Java - -```java -package zouye; - -public class Employee { - private String name; - public double earning(){ - return 0.0; - } - public String getInfo(){ - return "姓名:"+name+"实发工资:"+earning(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Employee() { - } - - public Employee(String name) { - this.name = name; - } -} - -``` - -```java -package zouye; - -public class MyDate { - private int year; - private int month; - private int day; - public String getInfo() { - return year+"年"+month+"月"+day+"日"; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - - public int getMonth() { - return month; - } - - public void setMonth(int month) { - this.month = month; - } - - public int getDay() { - return day; - } - - public void setDay(int day) { - this.day = day; - } - - public MyDate(int year, int month, int day) { - this.year = year; - this.month = month; - this.day = day; - } - - public MyDate() { - } -} - -``` - -```java -package zouye; - -public class SalaryEmployee extends Employee{ - private double salary; - private MyDate birthday; - - public double getSalary() { - return salary; - } - - public void setSalary(double salary) { - this.salary = salary; - } - - public MyDate getBirthday() { - return birthday; - } - - public void setBirthday(MyDate birthday) { - this.birthday = birthday; - } - - public SalaryEmployee(double salary, MyDate birthday) { - this.salary = salary; - this.birthday = birthday; - } - - public SalaryEmployee(String name, double salary, MyDate birthday) { - super(name); - this.salary = salary; - this.birthday = birthday; - } - - public SalaryEmployee() { - } - - @Override - public double earning(){ - return salary; - } - - @Override - public String getInfo() { - return super.getInfo()+"生日:"+birthday.getInfo(); - } -} - -``` - -```java -package zouye; - -public class HourEmployee extends Employee{ - double hour; - double hourmoney; - - public HourEmployee() { - } - - public HourEmployee(double hour, double hourmoney) { - this.hour = hour; - this.hourmoney = hourmoney; - } - - @Override - public double earning() { - return hour*hourmoney; - } - - @Override - public String getInfo() { - return super.getInfo()+"时薪:"+hourmoney+"工作小时数:"+hour; - } -} - -``` - -```java -package zouye; - -public class Manager extends SalaryEmployee{ -private double Bonusratio; - - public double getBonusratio() { - return Bonusratio; - } - - public void setBonusratio(double bonusratio) { - Bonusratio = bonusratio; - } - - @Override - public double earning() { - return super.earning()*(1+Bonusratio); - } - - @Override - public String getInfo() { - return super.getInfo()+"奖金比例:"+Bonusratio; - } -} - -``` - -```java -package zouye; - -public class Test { - public static void main(String[] args) { - Employee[] arr=new Employee[3]; - SalaryEmployee s = new SalaryEmployee(); - MyDate m1 = new MyDate(2001,5,6); - HourEmployee h1 = new HourEmployee(8,20); - s.setName("张三"); - s.setSalary(5000); - arr[0]=s; - - HourEmployee h2 = new HourEmployee(10,15); - h2.setName("李四"); - arr[1]=h2; - - Manager m = new Manager(); - MyDate m2 = new MyDate(1998,3,6); - m.setName("王五"); - m.setSalary(12000); - m.setBonusratio(0.2); - arr[2]=m; - - double sum=0; - for (int i = 0; i < arr.length; i++) { - System.out.println(arr[i].getInfo()); - sum += arr[i].earning(); - } - System.out.println("实发工资总额为:"+sum); -} - -``` -~~~ - diff --git "a/19 \351\231\210\345\246\203/20230510.md" "b/19 \351\231\210\345\246\203/20230510.md" new file mode 100644 index 0000000000000000000000000000000000000000..d856ae186642f26e2a5959426bc30378a23c8598 --- /dev/null +++ "b/19 \351\231\210\345\246\203/20230510.md" @@ -0,0 +1,38 @@ +# 作业 + +~~~java +```java +package zuoye; +import java.util.Scanner; + +public class Z { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int x; + int y; + while (true) { + try { + System.out.println("请输入第一个数字"); + x = sc.nextInt(); + System.out.println("请输入第二个数字"); + y = sc.nextInt(); + } catch (Exception e) { + System.out.println("输入内容有误"); + sc.next(); + continue; + }sum(x,y); + break; + } + } +public static void sum(int x,int y){ + int a=x+y; + System.out.println(a); +} + } + + + + +``` +~~~ +