java接口的实例:打印工资单

import java.util.Scanner;
/*
 * 工资:基本工资,加班补助,奖金
 * 扣除:养老保险,医疗保险,还有超过5000的收个人所得税的3%
 * 
 * 
 * 
 * 
 **/
public class Zong implements Work,RenShe,ShuiWu{
	double jb,jz,jj;
	public void setJb(double jb)
	{
		this.jb = jb;
	}
	public  double getJb()
	{
		return this.jb;
	}
	public void setJz(double jz)
	{
		this.jz = jz;
	}
	public double getJz()
	{
		return this.jz;
	}
	public void setJj(double jj)
	{
		this.jj = jj;
	}
			
	public  double getJj()
	{
		return this.jj;
	}
	 public double yangLao(double gz)
	 {
		 return (gz * 0.12);
	 }
     public double yiLiao(double gz)
     {
    	 return (gz * 0.1);
     }
     public double suoDe(double gz)
     {
    	 return (gz * 0.03);
     }


	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double jb,jz,jj,gz,zong;
		Zong z = new Zong();
		Scanner input = new Scanner(System.in);
		System.out.print("请输入基本工资:");
		jb = input.nextDouble();
		z.setJb(jb);
		System.out.print("请输入加班补助: ");
		jz = input.nextDouble();
		z.setJz(jz);
		System.out.print("请输入奖金: ");
		jj = input.nextDouble();
		z.setJj(jj);
		gz = jb + jz + jj;
		System.out.println("养老保险:" + z.yangLao(gz));
		System.out.println("医疗保险: " + z.yiLiao(gz));
		if(gz > 5000)
		{
			System.out.println("个人所得税: " + z.suoDe(gz));
			zong = gz - z.yangLao(gz) - z.yiLiao(gz) - z.suoDe(gz);
		}
		else
		{
			zong = gz - z.yangLao(gz) - z.yiLiao(gz);
		}
		System.out.println("总工资: " + zong);
		

	}

}

底下是接口

public interface Work {
	public abstract void setJb(double jb);
	public abstract double getJb();
	public abstract void setJz(double jz);
	public abstract double getJz();
	public abstract void setJj(double jj);
	public abstract double getJj();

}

public interface RenShe {
     public abstract double yangLao(double z);
     public abstract double yiLiao(double z);
}

public interface ShuiWu {
      public abstract double suoDe(double gz);
     
}

你可能感兴趣的:(Java)