package com.zuoye.dome1;
/**
* Employee:
* 这是所有员工总的父类,
* 属性:员工的姓名,员工的生日月份。
* 方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元
*/
public class Employee {
private String name;
private int Birthday;
public Employee() {
}
public Employee(String name, int birthday) {
this.name = name;
Birthday = birthday;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBirthday() {
return Birthday;
}
public void setBirthday(int birthday) {
Birthday = birthday;
}
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", Birthday=" + Birthday +
'}';
}
public double getSalary(int month){
if (this.Birthday == month) {
return 100;
}
return 0;
}
}
package com.zuoye.dome1;
/**
SalariedEmployee:
Employee的子类,拿固定工资的员工。
属性:月薪
*/
public class SalariedEmployee extends Employee{
private double monthlySalary;//月薪
public SalariedEmployee() {
}
public SalariedEmployee(String name, int birthday, double monthlySalary) {
super(name, birthday);
this.monthlySalary = monthlySalary;
}
@Override
public double getSalary(int month) {
return monthlySalary+super.getSalary(month);
}
}
package com.zuoye.dome1;
/**
* HourlyEmployee:
* Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
* 属性:每小时的工资、每月工作的小时数
*/
public class HourlyEmployee extends Employee{
private double hourlywage; //每小时的工资
private int Hour; //每月工作的小时数
public HourlyEmployee() {
}
public HourlyEmployee(double hourlywage, int hour) {
this.hourlywage = hourlywage;
Hour = hour;
}
public HourlyEmployee(String name, int birthday, double hourlywage, int hour) {
super(name, birthday);
this.hourlywage = hourlywage;
Hour = hour;
}
public double getHourlywage() {
return hourlywage;
}
public void setHourlywage(double hourlywage) {
this.hourlywage = hourlywage;
}
public int getHour() {
return Hour;
}
public void setHour(int hour) {
Hour = hour;
}
@Override
public double getSalary(int month) {
if ( Hour>160) {
return hourlywage*160+(Hour-160)*hourlywage*1.5 +super.getSalary(month);
}
return hourlywage*Hour + super.getSalary(month);
}
}
package com.zuoye.dome1;
/**
SalesEmployee:
Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
*/
public class SalesEmployee extends Employee{
private int yuexiao;
private double tcl;
@Override
public double getSalary(int month) {
return yuexiao*tcl+super.getSalary(month);
}
public SalesEmployee() {
}
public SalesEmployee(int yuexiao, double tcl) {
this.yuexiao = yuexiao;
this.tcl = tcl;
}
public SalesEmployee(String name, int birthday, int yuexiao, double tcl) {
super(name, birthday);
this.yuexiao = yuexiao;
this.tcl = tcl;
}
public int getYuexiao() {
return yuexiao;
}
public void setYuexiao(int yuexiao) {
this.yuexiao = yuexiao;
}
public double getTcl() {
return tcl;
}
public void setTcl(double tcl) {
this.tcl = tcl;
}
}
package com.zuoye.dome1;
/**
* BasePlusSalesEmployee:
* SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
* 属性:底薪。
*/
public class BasePlusSalesEmployee extends SalesEmployee{
private double basicSalary;
@Override
public double getSalary(int month) {
return basicSalary+super.getSalary(month);
}
public BasePlusSalesEmployee() {
}
public BasePlusSalesEmployee(int yuexiao, double tcl) {
super(yuexiao, tcl);
}
public BasePlusSalesEmployee(String name, int birthday, int yuexiao, double tcl) {
super(name, birthday, yuexiao, tcl);
}
public BasePlusSalesEmployee(double basicSalary) {
this.basicSalary = basicSalary;
}
public BasePlusSalesEmployee(int yuexiao, double tcl, double basicSalary) {
super(yuexiao, tcl);
this.basicSalary = basicSalary;
}
public BasePlusSalesEmployee(String name, int birthday, int yuexiao, double tcl, double basicSalary) {
super(name, birthday, yuexiao, tcl);
this.basicSalary = basicSalary;
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
}
package com.zuoye.dome1;
public class Test {
public static void main(String[] args) {
SalariedEmployee a = new SalariedEmployee("小明", 6,10000);
System.out.println("小明工资为"+a.getSalary(1));
System.out.println("小明过生日时工资为"+a.getSalary(6));
HourlyEmployee b = new HourlyEmployee("小刚", 6,120,360);
System.out.println("小刚工资为"+b.getSalary(1));
System.out.println("小刚过生日时工资为"+b.getSalary(6));
SalesEmployee c = new SalesEmployee("小李", 3,12000,50);
System.out.println("小李工资为"+c.getSalary(1));
System.out.println("小李过生日时工资为"+c.getSalary(3));
BasePlusSalesEmployee d = new BasePlusSalesEmployee("小刘",3,12300,50,2000);
System.out.println("小刘工资为"+d.getSalary(1));
System.out.println("小刘过生日时工资为"+d.getSalary(3));
}
}
小明工资为10000.0
小明过生日时工资为10100.0
小刚工资为55200.0
小刚过生日时工资为55300.0
小李工资为600000.0
小李过生日时工资为600100.0
小刘工资为617000.0
小刘过生日时工资为617100.0
package com.zuoye.dome2;
public interface Shape {
//周长
public double getArea();
//求面积
public double getLength();
public final static double PI=3.14;
}
package com.zuoye.dome2;
/**
* 矩形
*/
public class Rect implements Shape{
private double long1; //长
private double width; //宽
public Rect() {
}
public Rect(double long1, double width) {
this.long1 = long1;
this.width = width;
}
public double getLong1() {
return long1;
}
public void setLong1(double long1) {
this.long1 = long1;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
@Override
public String toString() {
return "Rect{" +
"long1=" + long1 +
", width=" + width +
'}';
}
//周长
@Override
public double getArea() {
return (long1+width)*2;
}
//面积
@Override
public double getLength() {
return long1*width;
}
}
package com.zuoye.dome2;
/**
* Circle(圆形)
*/
public class Circle implements Shape{
private double radius; //半径
//周长
@Override
public double getArea() {
return 2*radius*PI;
}
//面积
@Override
public double getLength() {
return radius*radius*PI;
}
public Circle() {
}
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
}
package com.zuoye.dome2;
//Square(正方形)
public class Square extends Rect{
public Square() {
}
public Square(double long1, double width) {
super(long1, width);
}
//周长
@Override
public double getArea() {
return 2*(super.getLong1()+super.getWidth());
}
//面积
@Override
public double getLength() {
return super.getLong1()*super.getWidth();
}
}
package com.zuoye.dome2;
public class Test {
public static void main(String[] args) {
//矩形
Rect s1 = new Rect();
s1.setLong1(2);
s1.setWidth(3);
double a1= s1.getArea();
double b1= s1.getLength();
System.out.println("该矩形周长为:"+a1);
System.out.println("该矩形面积为:"+b1);
//圆
Circle s2 = new Circle();
s2.setRadius(3);
double a2= s2.getArea();
double b2= s2.getLength();
System.out.println("该圆周长为:"+a2);
System.out.println("该圆面积为:"+b2);
//正方形
Square s3 = new Square();
s3.setLong1(2);
s3.setWidth(2);
double a3= s3.getArea();
double b3= s3.getLength();
System.out.println("该正方形周长为:"+a3);
System.out.println("该正方形面积为:"+b3);
}
}
该矩形周长为:10.0
该矩形面积为:6.0
该圆周长为:18.84
该圆面积为:28.26
该正方形周长为:8.0
该正方形面积为:4.0