java第十五次作业
package Vehicle; public abstract class ColaEmployee { String name; int month ; int day ; int year; public ColaEmployee() { } public ColaEmployee(String name, int month, int day, int year) { this.name = name; this.month = month; this.day = day; this.year = year; } abstract double getSalary(int month); }
package Vehicle; public class Company { public static void getSalary(int month,ColaEmployee c) { System.out.println(month+"月"+c.name+"的工资是: "+c.getSalary(month)); } }
package Vehicle; public class HourlyEmployee extends ColaEmployee{ double hsalary; int h; public HourlyEmployee() { } public HourlyEmployee(String name, int month, int day, int year,double hsalary,int h) { super(name, month, day, year); this.hsalary=hsalary; this.h=h; } double getSalary(int month) { double salary=0; if(h>160) { salary=160*hsalary+(h-160)*hsalary*1.5; }else { salary=h*hsalary; } if(month==this.month) { salary+=100; } return salary; }
}
package Vehicle; public class SalariedEmployee extends ColaEmployee{ double salary; public SalariedEmployee() { } public SalariedEmployee(String name, int month, int day, int year,double salary) { super(name, month, day, year); this.salary=salary; } double getSalary(int month) { if(month==this.month) { salary+=100; } return salary; } }
package Vehicle; public class SalesEmployee extends ColaEmployee { double msalary; double t; //提成 public SalesEmployee() { } public SalesEmployee(String name, int month, int day, int year,double msalary,double t) { super(name, month, day, year); this.msalary=msalary; this.t=t; } double getSalary(int month) { double salary=msalary*t; if(month==this.month) { salary+=100; } return salary; } }
package Vehicle; public class TestCompany { public static void main(String[] args) { ColaEmployee[] a=new ColaEmployee[3]; a[0]=new SalariedEmployee("小红",5,26,1999,3500); a[1]=new HourlyEmployee("小海",7,20,1998,300,6); a[2]=new SalesEmployee("小白",6,14,1997,20000,0.2); for(ColaEmployee c:a) { Company.getSalary(5, c); } } }
package test; import java.util.Scanner; public interface test { } class Apple implements test { public Apple() { System.out.println("创建了一个苹果对象"); } } class Banana implements test { public Banana() { System.out.println("创建了一个香蕉对象"); } } class Putao implements test { public Putao() { System.out.println("创建了一个葡萄对象"); } } class Gardener { public test create() { test f = null; Scanner input = new Scanner(System.in); String name = input.next(); if (name.equals("苹果")) { f = new Apple(); } else if (name.equals("香蕉")) { f = new Banana(); } else if (name.equals("葡萄")) { f = new Putao(); } else { System.out.println("不会种"); } return f; } }
package test; public class test1 { /** * @param args */ public static void main(String[] args) { Gardener g = new Gardener(); g.create(); } }
package test;
import java.util.Scanner;
public interface test {
} class Apple implements test { public Apple() { System.out.println("创建了一个苹果对象"); } } class Banana implements test { public Banana() { System.out.println("创建了一个香蕉对象"); } } class Putao implements test { public Putao() { System.out.println("创建了一个葡萄对象"); } } class Gardener { public test create() { test f = null; Scanner input = new Scanner(System.in); String name = input.next(); if (name.equals("苹果")) { f = new Apple(); } else if (name.equals("香蕉")) { f = new Banana(); } else if (name.equals("葡萄")) { f = new Putao(); } else { System.out.println("不会种"); } return f; } }