第十五周java作业

Posted 丁朝明

tags:

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

 

package Cola;

public class ColaEmployee {
    protected String name;
    protected int month;
    private int birthday;
    
    public String getName() {
     return name;
 }
 public void setName(String name) {
     this.name = name;
 }
 public int getMonth() {
     return month;
 }
 public void setMonth(int month) {
     this.month = month;
 }
 public int getBirthday() {
     return birthday;
 }
 public void setBirthday(int birthday) {
     this.birthday = birthday;
 }
 public ColaEmployee(){
        
    }
 public ColaEmployee(String name,int month,int birthday){
        super();
        this.month =month;
        this.name =name;
        this.birthday =birthday;
    }
    public double getSalary(int month){
     return 0;
    }
 }


package Cola;

public class SalariedEmployee extends ColaEmployee {
    protected double money;
    public  SalariedEmployee (){
        
    }
    public  SalariedEmployee (String name,int month,int birthday,double money){
        super(name,month,birthday);
        this.money=money;
    }
    public double getSalary(int month){
        if(super.getMonth()==super.getBirthday()){
            return money+100;
        }else{
        return money;
    }
    }
}

package Cola;

public class HourlyEmployee extends ColaEmployee {
    protected int hour;
    protected int hourmoney;
    public  HourlyEmployee (){
        
    }
    public  HourlyEmployee (String name,int month,int birthday,int hour,int hourmoney){
        super(name,month,birthday);
        this.hour =hour;
        this.hourmoney=hourmoney;
    }
    public double getSalary(int month){
        if(super.getMonth()==super.getBirthday()){
        if(hour>160)
            return hourmoney*160+(hour-160)*hourmoney+100;
        else
            return hourmoney*hour+100;
        }else{
            if(hour>160)
                return hourmoney*160+(hour-160)*hourmoney;
            else
                return hourmoney*hour;
    }
    }
}

package Cola;

public class SalesEmployee extends ColaEmployee {
    protected double monthsales;
    protected double per;
    public  SalesEmployee (String name,int month,int birthday,double monthsales,double per){
        super(name,month,birthday);
        this.monthsales =monthsales;
        this.per =per;
    }
    public double getSalary(int month){
    if(super.getMonth()==super.getBirthday())
       return +monthsales*per+100;
    else
    return monthsales*per;
    }
}

    package Cola;

    public class Company {
          public void getSalary(ColaEmployee c,int month){
              System.out.println(c.name +"在"+month+"月的月薪为"+c.getSalary(month)+"元");
          }
        }

package Cola;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        ColaEmployee c1[]={new SalariedEmployee("sam",3,4,6666),
                new HourlyEmployee("cdv",3,5,110,888),
                new SalesEmployee("asd",3,7,6666,0.3)
};
for(int i=0;i<c1.length ;i++){
 new Company().getSalary( c1[i], 8);
}
}

}

 

 

package zuoye;

import java.util.Scanner;



public class text {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        garderner g = new garderner();
        g.creat();
    }

}
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 garderner{
    public fruit creat() {
        fruit f = null;
        Scanner input = new Scanner(System.in);
        String name = input.next();
        if(name.equals("苹果")) {
            f = (fruit) new apple();
        }
        if(name.equals("香蕉")) {
            f = (fruit) new banana();
        }
        if(name.equals("葡萄")) {
            f = (fruit) new putao();
        }
        return f;
    }
    
}
interface fruit{
    
}

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

第十五周Java作业

Java程序第十五周作业

Java第十五周作业

Java第十五周作业

Java第十五周作业

Java第十五周作业