大家好,欢迎来到IT知识分享网。
展开全部
我给你简单的代62616964757a686964616fe4b893e5b19e31333335313761码 那些行为的话 把通用的写在person中 个别的写在个别类中 如: 学生学习行为
写在学生类中
代码如下
/**
* person抽象类
*
* @author
*
*/
public abstract class Person {
private String name;
private int age;
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.name+”\t”+this.age;
}
}
/**
* 学生接口
* @author sunquan
*
*/
public interface Students {
}
/**
* 老师接口
* @author sunquan
*
*/
public interface Teachers {
}
/**
* 家长接口
* @author sunquan
*
*/
public interface KidHeads {
}
/**
* 学生类
* @author sunquan
*
*/
public class Student extends Person implements Students {
public Student(String name, int age) {
super(name, age);
// TODO Auto-generated constructor stub
}
private int score;//学生成绩
private String level;//学生成绩等级
private String name;
public Student(String name, int age, int score) {
super(name, age);
this.name = name;
this.score = score;
if(score>=90&&score<=100){
this.level=”优秀”;
}
if(score>=80&&score<90){
this.level=”良好”;
}
if(score>=70&&score<79){
this.level=”一般”;
}
if(score>=60&&score<69){
this.level=”及格”;
}
if(score<60){
this.level=”差”;
}
}
//set和get
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/**
* 老师类
* @author sunquan
*
*/
public class Teacher extends Person implements Teachers {
public Teacher(String name, int age) {
super(name, age);
// TODO Auto-generated constructor stub
}
}
/**
* 家长类
* @author sunquan
*
*/
public class KidHead extends Person implements KidHeads {
public KidHead(String name, int age) {
super(name, age);
// TODO Auto-generated constructor stub
}
}
最后是测试类
/**
* 测试类
*
* @author sunquan
*
*/
public class Test {
public static void main(String[] args) {
//第四题
System.out.println(“第四题************:”);
Student stu1 = new Student(“张三(001)”,19,96);
Student stu2 = new Student(“张三(002)”,18,85);
Student stu3 = new Student(“张三(003)”,19,76);
Student stu4 = new Student(“张三(004)”,19,66);
Student stu5 = new Student(“张三(005)”,19,56);
Teacher tea = new Teacher(“李四”, 43);
KidHead kh = new KidHead(“毛二”, 44);
System.out.println(stu1);
System.out.println(tea);
System.out.println(kh);
//第五题
System.out.println();
System.out.println(“第五题************:”);
System.out.println(stu1.getName()+”:”+stu1.getLevel());
System.out.println(stu2.getName()+”:”+stu2.getLevel());
System.out.println(stu3.getName()+”:”+stu3.getLevel());
System.out.println(stu4.getName()+”:”+stu4.getLevel());
System.out.println(stu5.getName()+”:”+stu5.getLevel());
//第六题
System.out.println();
System.out.println(“第六题************:”);
//输出优秀学生
List stu =new ArrayList();
stu.add(stu1);
stu.add(stu2);
stu.add(stu3);
stu.add(stu4);
stu.add(stu5);
for (Student student : stu) {
if(student.getLevel()==”优秀”){
System.out.println(student.getName());
}
}
//如果是按分数排的话需要求出stu中score的最大值
int max = stu.get(0).getScore();
for (int i = 0; i
if(max
max = stu.get(i).getScore();
}
}
System.out.print(“最优秀的学生是:”);
for (Student student : stu) {
if(student.getScore()==max){
System.out.println(student.getName());
}
}
}
}
题的意思我是看懂了 但是你的详细需求是后面看到的 你自己认真看看代码就会明白的。
其他你看看上楼的回答就知道了
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/10701.html