#千锋逆战班,ssf# 在千锋“逆战”学习第 18天, 每个人生阶段都需要努力去扮好自己的角色,越努力越轻松,越坚强越幸运! 加油

第三题:
(1) void md()、void ma()、void mb()、void mc()
(2) (IA) ic.ma(); (IB) ic.mb(); ic.mc(); (ID) id.md();
(3) True、 true、 true、 true、 true
第四题:true、 true、 true、 true
第五题:ACDE
第六题:Red Light shine in Red Yellow Light shine in Yellow Green Light shine in Green
第七题:TeacherA teach java Teacher8 teach java
第八题:1.for(int i = 0; I < as.length; i++ ){
As[i].eat();
}
2.for(int I = 0; I < as.length; i++){
If(as[i] instanceof Pet){
Pet p = (Pet)as[i];
p.play();
}
}
第九题“
package com.qf.day18.t3.usb;
import java.util.Scanner;
public class TestEmployee {

public static void main(String[] args) {
	
	Employee[] es = new Employee[4];
	
	es[0] = new SalariedEmployee("John",5,5000);
	es[1] = new HourlyEmployee("Tom",3,24,170);
	es[2] = new SalesEmployee("Lucy", 7,10000,0.04);
	es[3] = new BasePlusSalesEmployee("James",8,100000,0.03,5000);
	//统计加班费
	double sum = 0;
	for(int i = 0; i < es.length; i++) {
		if(es[i] instanceof Overtime) {
			Overtime ot = (Overtime) es[i];
			sum += ot.getOvertimePay();
		}
	}
	System.out.println(sum);


}

}
interface Overtime{
double getOvertimePay();
}
class Employee{
private String name;
private int birthMonth;
public Employee(String name,int birthMonth) {
this.name = name;
this.birthMonth = birthMonth;
}
public String getName() {
if(this.birthMonth == month) return 100;{
else return 0;
}

}

}
class SalariedEmployee extends Employee implements Overtime{
private double salary;
public SalariedEmployee(String name,int birthMonth,double salary) {
//把name,birthMonth,两个参数传给父类,设置父类属性
super(name,birthMonth);
this.salary = salary;

}
public double getSalary(int month) {
	return salary + super.getSalary(month);
	
}
public double getOvertimePay() {
	return 2000;
	
}

}
class HourlyEmployee extends Employee{
private double salaryPerHour;
private int hours;
public HourlyEmployee(String name, int birthMonth, double salaryPerHour, int hours) {
super(name,birthMonth);
this.salaryPerHour = salaryPerHour;
this.hours = hours;
}
public double getSalary(int month) {
double result = 0;
if(hours > 160) {
result = 160this.salaryPerHour + (hours-160)this.salaryPerHour1.5;
}else {result = this.hours
this.salaryPerHour;
return result + super.getSalary(month);
}
}

}

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

}

class BasePlusSalesEmployee extends SalesEmployee implements Overtime{
private double basedSalary;
public BasePlusSalesEmployee(String name,int birthMonth,double sales, double rate,double basedSalary) {
this.basedSalary = basedSalary;

}
public double getSalary(int month) {
	return this.basedSalary + super.getSalary(month);
	
}
public double getOvertimePay() {
	return 1000;
	
}

}

第十题
如果实现Servicelmpl接口,则必须实现其所有方法,而如果继承AbstractService类,则只需要覆盖其中我们感兴趣的方法即可。在实际开发中,往往既提供接口,又提供抽象类。既可以提供接口灵活性的基础,也能够使用抽象类来减少代码量

第十一题

import java.util.Scanner;

public class Gedebahe {
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int m=scan.nextInt();
if(m%2!=0 || m<=6) {
System.out.println(“输入错误…”);
}
for(int n=2;n<=m;n++){
for(int y=m;y>n;y–){
if(fan(n)&&fan(y)){
if(n+ym) {
System.out.print(m+"="+y+"+"+n+" “);
System.out.print(”\n");
}
}
}
}
scan.close();
}
public static boolean fan(int x){ //素数判断
for(int i=2;i<x;i++){
if(x%i
0){
return false;
}
}
return true;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值