#千锋逆战班,作业2.26#

3

I.

	ma() , mb() , mc() , md()

II.

public class TestClassE{
	public static void main(String[] args){
		Ic ic = new ClassE();
		((ClassE) ic).ma();
		((ClassE) ic).mb();
		ic.mc();
		((ClassE) ic).md();
	}
}

III.

	true
	true
	true
	true
	true
4
	ture
	true
	true
	true
5
	ACDE
6
	Red Light shine in Red
	Yellow Light shine in Yellow
	Green Light shine in Green
7
	TeacherA teach Java
	TeacherB teach Java
8
		//1
		for(int i = 0; i < as.length, i++){
			as[i].eat();	
		}
		//2
		for(int i = 0; i < as.length, i++){
			((Pet)as[i]).play();	
		}
9
package company;

public class TestEmployee {

	public static void main(String[] args) {
		Employee[] all = new Employee[5];
		all[0] = new SalariedEmployee("tom",7,1000);
		all[1] = new BasePlusSalesEmployee("mike", 8, 4000, 0.5, 1000);
		all[2] = new HourlyEmployee("jim", 1, 15, 170);
		all[3] = new SalesEmployee("annie", 7, 5000, 0.7);
		getExtraPay(all,7);
	}
	
	public static void getExtraPay(Employee[] all , int month){
		double extraPay = 0;
		for(int i = 0; i < all.length; i++){
			if(all[i] instanceof ExtraPay){
				extraPay += ((ExtraPay)all[i]).extraPay();
			}
		}
		System.out.println(extraPay);
	}

}

abstract class Employee{
	private String name;
	private int month;
	
	public Employee(String name, int month) {
		super();
		this.name = name;
		this.month = month;
	}

	public double getSalary(int month){
		if(this.month == month){
			return 100;
		}
		return 0;
	}
	
	
}

class SalariedEmployee extends Employee implements ExtraPay{
	private double salary;

	public SalariedEmployee(String name, int month, double salary) {
		super(name, month);
		this.salary = salary;
	}

	public double getSalary(int month) {
		salary += super.getSalary(month) + this.extraPay();
		return salary;
	}

	@Override
	public double extraPay() {
		
		return 2000;
	}
	
}

class HourlyEmployee extends Employee{
	private double hourlySalary;
	private int hours;
	public HourlyEmployee(String name, int month, double hourlySalary, int hours) {
		super(name, hours);
		this.hourlySalary = hourlySalary;
		this.hours = hours;
	}
	public double getSalary(int month){
		double salary;
		if(hours <= 160){
			salary = hours * hourlySalary + super.getSalary(month);
			return salary;
		}
		salary = 160 * hourlySalary + (hours - 160) * hourlySalary * 1.5 + super.getSalary(month);
		return salary;
	}
	
}

class SalesEmployee extends Employee{
	private double sales;
	private double rate;
	public SalesEmployee(String name, int month, double sales, double rate) {
		super(name, month);
		this.sales = sales;
		this.rate = rate;
	}
	public double getSalary(int month){
		double salary;
		salary = rate * sales +super.getSalary(month);
		return salary;
	}
}

class BasePlusSalesEmployee extends SalesEmployee implements ExtraPay{
	private double baseSalary;
	public BasePlusSalesEmployee(String name, int month, double sales, double rate, double baseSalary) {
		super(name, month, sales, rate);
		this.baseSalary =baseSalary;
	}
	public double getSalary(int month){
		double salary;
		salary = super.getSalary(month) + baseSalary + this.extraPay();
		return salary;
	}
	@Override
	public double extraPay() {
		return 1000;
	}
}

interface ExtraPay{
	double extraPay();
}
10

区别:第一种MyService需覆盖ServiceInterface接口中包含的所有方法,第二种则不需要。
AbstractService作用:为MyService提供默认方法。

11
import java.util.Scanner;
public class TestT11 {

	public static void main(String[] args) {		
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个大于6的整数");
		int num = input.nextInt();
		split(num);
	}


	public static void split(int num){
		if(num > 6 && num % 2 == 0){
			for(int i = 2; i < num; i++){
				if(check(i) && check(num-i)){
					System.out.println(num + "=" + i + "+" + (num - i));
					return;
				}
			}
		}
		System.out.println("输入有误");
	}
	
	
	public static boolean check(int numi){
		for(int i = 2; i < numi; i++){
			if(numi % i == 0){
				return false;
			}
		}	
		return true;
	}
}
笔记

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值