用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

员工工资抽象类

2018-09-29 作者:云代码会员举报

[java]代码库

import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
         int salary1 = scan.nextInt();
         Employee E1 = new Manager(salary1);
         System.out.println(E1.getSalary());
         int salary2 =scan.nextInt();
         int royalty =scan.nextInt();
         Employee E2 = new Salesman(salary2, royalty);
         System.out.println(E2.getSalary());
         int salary3 = scan.nextInt();
         int num =scan.nextInt();
         Employee E3 = new Worker(num, salary3);
         System.out.println(E3.getSalary());

         scan.close(); 
	}        
} 
abstract class Employee{
	private int salary;
	public Employee(int s) {
		salary = s;
	}
	public int getS() {
		return salary;
	}
	public abstract int getSalary();
}

class Manager extends Employee{
	public Manager(int s) {
		super(s);
	}
	public int getSalary() {
		return super.getS();
	}
}

class Salesman extends Employee{
	private int royalty;
	public Salesman(int s, int r) {
		super(s);
		royalty = r;
	}
	public int getSalary() {
		return super.getS()+royalty;
	}
}

class Worker extends Employee{
	private int num;
	public Worker(int s, int n) {
		super(s);
		num = n;
	}
	public int getSalary() {
		return super.getS()*num;
	}
}


分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。