Java第十二次作业

Posted 万家乐

tags:

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

1.

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("zs",1,3900);
        ColaEmployee h2 = new HourlyEmployee("ls",2,170,10);
        ColaEmployee h3 = new HourlyEmployee("ww",3,100,10);
        ColaEmployee s4 = new SalesEmployee("zl",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 homework15;

interface Fruit {

}

package homework15;

public class Apple implements Fruit {

    public Apple() {
        System.out.println("创建了一个苹果对象");

    }

}
package homework15;

public class Banana implements Fruit {

    public Banana() {
        System.out.println("创建了一个香蕉对象");

    }

}
复制代码
复制代码
package homework15;

public class Grape implements Fruit{

    public Grape () {
        System.out.println("创建了一个葡萄对象");

    }

}
package homework15;

import java.util.Scanner;

public class Gardener {
    Fruit Create(){
        System.out.println("请输入需要创建的对象名……");
        Scanner in = new Scanner (System.in);
        String f = in.next();

        Fruit fruit = null;
        if("苹果".equals(f)){
            fruit =  new Apple();
        }
        if("葡萄".equals(f)){
            fruit =  new Grape();
        }
        if("香蕉".equals(f)){
            fruit = new Banana();
        }
        return fruit;
    }
}
package homework15;

public class Test1 {
    public static void main(String[] args) {
        new Gardener().Create();
    }

}

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

201621123042《java程序设计》第十二次作业

Java第十二次作业

Java第十二次作业

Java第十二次作业

Java第十二次作业

java第十二次上机作业