Java程序第十五周作业

Posted sike2017

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java程序第十五周作业相关的知识,希望对你有一定的参考价值。

package com.homework10;

public abstract class ColaEmployee {
    String name;
    int year;
    int month;
    int day;
    double salary = 70000;

    ColaEmployee(String name, int year, int month, int day) {
        name = name;
        year = year;
        month = month;
        day = day;
    }

    abstract double getSalary(int month);
}

package com.homework10;

public class SalariedEmployee extends ColaEmployee {
    double monthSalary = 70000;
    SalariedEmployee(String name, int year, int month, int day) {
        super(name, year, month, day);
    }

    public double getSalary(int month) {
        if (month == this.month) {
            return monthSalary + 100;
        }
        return monthSalary;
    }
}

package com.homework10;

public class HourlyEmployee extends ColaEmployee {
    double hours = 241;
    double salaryPerHour = 70;
    HourlyEmployee(String name, int year, int month, int day) {
        super(name, year, month, day);
    }
    public double getSalary(int month) {
        if (hours > 160) {
            double moreHours = hours - 160;
            return salaryPerHour * moreHours * 1.5 + 160 * salaryPerHour;
        }
        return salaryPerHour * hours;
    }
}

package com.homework10;

public class SalesEmployee extends ColaEmployee {
    double sale = 1000;
    double rate = 0.01;

    SalesEmployee(String name, int year, int month, int day) {
        super(name, year, month, day);
    }

    double getSalary(int month) {
        return sale * rate;
    }
}

package com.homework10;

public abstract class ColaEmployee {
    String name;
    int year;
    int month;
    int day;
    double salary = 70000;

    ColaEmployee(String name, int year, int month, int day) {
        name = name;
        year = year;
        month = month;
        day = day;
    }

    abstract double getSalary(int month);
}

package com.homework10;

public class TestCompany {
    public static void main(String[] args) {
        ColaEmployee employees[] = new ColaEmployee[16];
        employees[0] = new SalariedEmployee("salariedEmployee", 2000, 1, 1);
        employees[1] = new HourlyEmployee("hourlyEmployee", 2000, 1, 1);
        employees[2] = new SalesEmployee("salesEmployee", 2000, 1, 1);
        Company company = new Company();
        for (int n = 0; n < 3; n++) {
            company.printInformation(employees[n], 7);
        }
    }
}

package com.homework10;

public class Apple {
    Apple() {
        System.out.println("apple");
    }
}

package com.homework10;

public class Banana {
    Banana() {
        System.out.println("banana");
    }
}



package com.homework10;

public class Grape {
    Grape() {
        System.out.println("grape");
    }
}




package com.homework10;

public class Gardener {
    Gardener() {
        System.out.println("gardener");
    }
}



package com.homework10;
import java.util.Scanner;

public class Assignment02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String result = scanner.next();
        Object object;
        if (result.equals("apple")) {
            object = new Apple();
        }
        else if (result.equals("banana")) {
            object = new Banana();
        }
        else if (result.equals("grape")) {
            object = new Grape();
        }
        else if (result.equals("gardener")) {
            object = new Gardener();
        }
        else {
            System.out.println("please input apple banana grape or gardener");
        }
    }
}

以上是关于Java程序第十五周作业的主要内容,如果未能解决你的问题,请参考以下文章

Java第十五周作业

第十五周Java作业

Java第十五周作业

Java第十五周作业

Java第十五周作业

Java第十五周作业