接口的应用之代码布局
创建接口
package cn.campsg.java.experiment;
public interface SeekJob {
float SEEKER_AVERAGE_SCORE=85.0f;//常量
public String getName();//接口中指定义方法不用实现public float getSeekerAverage();//获取求职者的专业课平均分
}
创建一个软件求职者并计算平均成绩
package cn.cmpsg.java.experiment.impl;
import cn.campsg.java.experiment.SeekJob;
public class SoftwareSeeker implements SeekJob{
public String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float[] getScores() {
return scores;
}
public void setScores(float[] scores) {
this.scores = scores;
}
float[] scores;
public SoftwareSeeker(){
}
public SoftwareSeeker(String name,float[] scores){
this.name=name;
this.scores=scores;
}
public float getSeekerAverage(){
return (float)(scores[0]*0.6+scores[1]*0.4);
}
public static void main(String[] args) {
}
}
创建一个大数据求职者的类并计算平均分
package cn.cmpsg.java.experiment.impl;
import cn.campsg.java.experiment.SeekJob;
public class BigDataSeeker implements SeekJob{
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float[] getScores() {
return scores;
}
public void setScores(float[] scores) {
this.scores = scores;
}
float[] scores;
public BigDataSeeker(){
}
public BigDataSeeker(String name,float[] scores){
this.name=name;
this.scores=scores;
}
public float getSeekerAverage(){
return (scores[0]+scores[1]/2);
}
public static void main(String[] args) {
}
}
创建一个HR类筛选员工
package cn.campsg.java.experiment;
import cn.cmpsg.java.experiment.impl.SoftwareSeeker;
public class HrMarketer {
public void seekJob(SeekJob s){
float[] scores={79,80};
SoftwareSeeker software=new SoftwareSeeker();
if(s.getSeekerAverage()>85.f){
System.out.println(s.getName()+"被公司录取了");
}else{
System.out.println(s.getName()+"成绩未达标,不予达标");
}
}
public static void main(String[] args) {
}
}
测试类
package cn.campsg.java.experiment;
import cn.cmpsg.java.experiment.impl.BigDataSeeker;
import cn.cmpsg.java.experiment.impl.SoftwareSeeker;
public class MainClass {
public static void main(String[] args) {
HrMarketer hr=new HrMarketer();
float[] f1={100.f,90.f};
SoftwareSeeker s1=new SoftwareSeeker("张小龙",f1);
SoftwareSeeker s2=new SoftwareSeeker("李小龙",new float[]{80.f,90.f});
BigDataSeeker b1=new BigDataSeeker("张艳红",new float[]{60.f,90.f});
BigDataSeeker b2=new BigDataSeeker("丽丽",new float[]{90.f,80.f});
hr.seekJob(s1);
hr.seekJob(s2);
hr.seekJob(b1);
hr.seekJob(b2);
}
}
上一篇: 详谈mysql order by in 的字符顺序(推荐)
下一篇: 原生AJAX写法实例分析