第十五周作业

package School.Day13;

public class ColaEmployee {
    String name;
    int month;
    double money;
    public double getSalary(int month){
        if (month == this.month) {
            return money = money + 100;
        }else{
            return money;
        }
    }

    @Override
    public String toString() {
        Double moneys = money;
        String s = moneys.toString();
        return s;
    }

    public ColaEmployee(String name, int month) {
        this.name = name;
        this.month = month;
    }

    public ColaEmployee() {
    }
}

  

package School.Day13;

public class SalariedEmployee extends ColaEmployee{

    public SalariedEmployee(String name,int month,double money) {
        this.name = name;
        this.month = month;
        this.money = money;
    }
    public SalariedEmployee() {

    }
}

  

package School.Day13;

public class HourlyEmployee extends ColaEmployee{
    public HourlyEmployee() {

    }

    public HourlyEmployee(String name,int month,int hour, int hourmoney) {
        this.name = name;
        this.month = month;
        if (hour > 160) {
            this.money = ((hour - 160) * hourmoney * 1.5) + (hourmoney * 160);
        }else{
            this.money = hour * hourmoney;
        }
    }
}

  

package School.Day13;

public class SalesEmployee extends ColaEmployee{
    int monthnumber;
    double ticheng;

    public SalesEmployee(String name,int month,int monthnumber, double ticheng) {
        this.name = name;
        this.month = month;
        this.monthnumber = monthnumber;
        this.ticheng = ticheng;
        money = monthnumber * ticheng * 0.01;
    }

    public SalesEmployee() {
    }
}

  

package School.Day13;

public class Company {
    ColaEmployee c;
    int hour;
    int moneynumber;
    int ti;

    public Company() {
    }

    public Company(ColaEmployee c, int hour, int moneynumber, int ti) {
        this.c = c;
        this.hour = hour;
        this.moneynumber = moneynumber;
        this.ti = ti;
    }

    public double Money(ColaEmployee c,int month){
        this.c = c;
        return this.c.getSalary(month);
    }

    public double HourMoney(ColaEmployee c,int month){
        this.c = c;
        return this.c.getSalary(month);
    }

    public double TiCheng(ColaEmployee c,int month){
        this.c = c;
        return this.c.getSalary(month);
    }
}

  

package School.Day13;

import java.text.CollationElementIterator;
import java.util.ArrayList;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        ArrayList<ColaEmployee> a = new ArrayList();
        Company c = new Company();
        ColaEmployee m1 = new SalariedEmployee("张三",1,3900);
        ColaEmployee h2 = new HourlyEmployee("李四",2,170,10);
        ColaEmployee h3 = new HourlyEmployee("王五",3,100,10);
        ColaEmployee s4 = new SalesEmployee("赵六",4,20000,10);
        a.add(m1);
        a.add(h2);
        a.add(h3);
        a.add(s4);
        Iterator i = a.iterator();
        while (i.hasNext()){
            System.out.println(i.next().toString());
        }
    }
}

  

2.

package School.Day13.HomeWork2;

public class Apple {
    public Apple(){
        System.out.println("创建了苹果🍎类对象");
    }
}

  

package School.Day13.HomeWork2;

public class Banana {
    public Banana() {
        System.out.println("创建香蕉🍌类对象");
    }
}

  

package School.Day13.HomeWork2;

public class Grape {
    public Grape() {
        System.out.println("创建葡萄🍇类对象");
    }
}

  

package School.Day13.HomeWork2;

import java.util.Scanner;

public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while(true) {
String in = s.next();
if (in.contains("苹果")) {
Apple a = new Apple();
} else if (in.contains("香蕉")) {
Banana b = new Banana();
} else if (in.contains("葡萄")) {
Grape g = new Grape();
} else{
System.out.println("啥也没有");
}
}
}
}

  

posted @ 2021-06-17 14:10  李芊  阅读(33)  评论(0编辑  收藏  举报