关于java接口类的题设计一个接
IStudent。java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor。
*/
package student;
/**
*
* @author
*/
public interface IStudent {
/**
* 读取学生姓名
* @return
*/
public String getName();
/**
* 设置学生姓名
* @param name
*/
public void setName(String name);
/**
* ...全部
IStudent。java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor。
*/
package student;
/**
*
* @author
*/
public interface IStudent {
/**
* 读取学生姓名
* @return
*/
public String getName();
/**
* 设置学生姓名
* @param name
*/
public void setName(String name);
/**
* 获取学号
* @return
*/
public String getStudentId();
/**
* 设置学号
*/
public void setStudentId(String studentId);
/**
* 判断是不是优秀
* @return
*/
public boolean isExcellent();
/**
* 输出所有信息
*/
public void output();
}
StudentG。
java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor。
*/
package student;
/**
*
* @author
*/
public class StudentG implements IStudent {
private String name;
//姓名
private String studentId;
//学号
private boolean cet4Pass = false;
//英语四级考试通过
private double score = 0。
0;
//综合成绩
public StudentG(String name, String sutdentId,
boolean cet4Pass, double score) {
= name;
udentId = sutdentId;
this。
cet4Pass = cet4Pass;
ore = score;
}
/**
* @return the name
*/
@Override
public String getName() {
return name;
}
/**
* @param name the name to set
*/
@Override
public void setName(String name) {
= name;
}
/**
* @return the cet4Pass
*/
public boolean isCet4Pass() {
return cet4Pass;
}
/**
* @param cet4Pass the cet4Pass to set
*/
public void setCet4Pass(boolean cet4Pass) {
this。
cet4Pass = cet4Pass;
}
/**
* @return the score
*/
public double getScore() {
return score;
}
/**
* @param score the score to set
*/
public void setScore(double score) {
ore = score;
}
/**
* @return the studentId
*/
@Override
public String getStudentId() {
return studentId;
}
/**
* @param studentId the studentId to set
*/
@Override
public void setStudentId(String studentId) {
udentId = studentId;
}
@Override
public boolean isExcellent() {
return Cet4Pass() && ( ore >= 85);
}
@Override
public String toString() {
return "本科生{" + "姓名=" + name
+ ", 学号=" + studentId
+ ", 英语四级考试通过=" + cet4Pass
+ ", 综合成绩=" + score + '}';
}
@Override
public void output() {
intln( String());
}
}
StudentM。
java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor。
*/
package student;
/**
*
* @author
*/
public class StudentM implements IStudent{
private String name;
//姓名
private String studentId;
//学号
private boolean cet6Pass = false;
//英语六级考试通过
private int count = 0;
//文章个数
public StudentM(String name, String sutdentId,
boolean cet6Pass, int count) {
= name;
udentId = sutdentId;
this。
cet6Pass = cet6Pass;
unt = count;
}
/**
* @return the name
*/
@Override
public String getName() {
return name;
}
/**
* @param name the name to set
*/
@Override
public void setName(String name) {
= name;
}
/**
* @return the studentId
*/
@Override
public String getStudentId() {
return studentId;
}
/**
* @param studentId the studentId to set
*/
@Override
public void setStudentId(String studentId) {
udentId = studentId;
}
/**
* @return the cet6Pass
*/
public boolean isCet6Pass() {
return cet6Pass;
}
/**
* @param cet6Pass the cet6Pass to set
*/
public void setCet6Pass(boolean cet6Pass) {
this。
cet6Pass = cet6Pass;
}
/**
* @return the count
*/
public int getCount() {
return count;
}
/**
* @param count the count to set
*/
public void setCount(int count) {
unt = count;
}
@Override
public String toString() {
return "研究生{" + "姓名=" + name
+ ", 学号=" + studentId
+ ", 英语六级考试通过=" + cet6Pass
+ ", 发表文章篇数=" + count + '}';
}
@Override
public boolean isExcellent() {
return Cet6Pass() && unt >= 1;
}
@Override
public void output() {
intln( String());
}
}
Student。
java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor。
*/
package student;
/**
*
* @author
*/
public class Student {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
IStudent[] students = new IStudent[5];
students[0] = new StudentG("G1","G001",true,90);
students[1] = new StudentG("G2","G002",false,60);
students[2] = new StudentG("G3","G003",true,80。
0);
students[3] = new StudentM("M1","M001",true,0);
students[4] = new StudentM("M1","M001",true,10);
for(int i = 0;i< students。
length;i++){
if(students[i]。isExcellent()){
int("EXCELENT : ");
students[i]。
output();
}
}
}
}
。收起