第十五周作业
Posted 计算机1903庞斯文
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十五周作业相关的知识,希望对你有一定的参考价值。
public class ColaEmployee { protected String name; protected int month; public ColaEmployee(){ super(); } public ColaEmployee(String name, int month) { super(); this.name = name; this.month = month; } public double getSalary(int month){ return 0; } }
public class SalariedEmployee extends ColaEmployee { int money; public SalariedEmployee() { super(); } public SalariedEmployee(String name,int month,int money) { super(name,month); this.money = money; } public double getSalary(int month){ if(super.month==month){ return money+100; }else{ return money; } } }
public class HourlyEmployee extends ColaEmployee{ int hmoney; int mday; public HourlyEmployee(){ super(); } public HourlyEmployee(String name,int month,int hmoney, int mday) { super(); this.hmoney = hmoney; this.mday = mday; } public double getSalary(int month){ if(super.month==month){ if(mday>160){ return hmoney*160*(mday-160)*1.5+100; }else{ return hmoney * mday + 100; } }else{ if(mday>160){ return hmoney*160+(mday-160)*1.5; }else{ return hmoney*mday; } } } }
public class SalesEmployee extends ColaEmployee { int monthlysales; double royaltyrate; public SalesEmployee(String name, int month, int monthlysales, double royaltyrate) { super(); this.monthlysales = monthlysales; this.royaltyrate = royaltyrate; } public double getSalary(int month){ if(super.month==month){ return monthlysales*royaltyrate+100; }else{ return monthlysales*royaltyrate; } } }
public class Copany extends ColaEmployee { public void getSalary(ColaEmployee c,int month){ System.out.println(c.name+"在"+month+"月的月薪为"+c.getSalary(month)+"元"); } }
public class Testcompany { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ColaEmployee c1[]={new SalariedEmployee("salare",4,70000), new HourlyEmployee("hourlye",4,200,30), new SalesEmployee("salese",4,17000,0.7) }; for (int i = 0; i < c1.length; i++) { new Copany().getSalary(c1[i], 4); } } }
import java.util.Scanner; public interface Fruit { } class Apple implements Fruit { public Apple() { System.out.println( "创建了一个苹果对象" ); } } class Banana implements Fruit { public Banana() { System.out.println( "创建了一个香蕉对象" ); } } class Putao implements Fruit { public Putao() { System.out.println( "创建了一个葡萄对象" ); } } class Gardener { public Fruit create() { Fruit 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; } } |
1
2
3
4
5
6
7
|
public class textfruit { public static void main(String[] args) { Gardener g = new Gardener(); g.create(); } } |
以上是关于第十五周作业的主要内容,如果未能解决你的问题,请参考以下文章