// 学生管理类
public class StudentMange {
// 创建arraylist存储学生对象
public ArrayList<Student> students = null;
// 初始化数据
public ArrayList<Student> init(){
Student student1 = new ComputerStudent("1001", "evan", 21, 99, 98);
Student student2 = new ArtStudent("1002", "daisy", 62, 59, "素描");
students.add(student1);
students.add(student2);
return students;
}
public void saveComputer(Student student){
students.add(student);
}
public ArrayList<Student> list(){
return students;
}
}
// 艺术生类
public class ArtStudent extends Student{
// 子类的属性
protected String Specialty;
//重写父类的方法
public void action(){
System.out.println("喜欢画画");
}
public void create(){
System.out.println("制造作品");
}
public String getSpecialty() {
return Specialty;
}
public void setSpecialty(String specialty) {
Specialty = specialty;
}
// 构造函数
public ArtStudent(){
}
public ArtStudent(String id, String name, int age, float score,String Specialty){
this.id = id;
this.name = name;
this.age = age;
this.score = score;
this.Specialty = Specialty;
}
}
// 计算机系学生
public class ComputerStudent extends Student{
// 子类的属性
protected float projectScore;
// 重写父类的方法
public void action(){
System.out.println("喜欢玩电脑");
}
public void programming(){
System.out.println("编程行为");
}
public float getProjectScore() {
return projectScore;
}
public void setProjectScore(float projectScore) {
this.projectScore = projectScore;
}
// 构造函数
public ComputerStudent(String id, String name, int age, float score, float projectScore) {
this.id = id;
this.name = name;
this.age = age;
this.score = score;
this.projectScore = projectScore;
}
public ComputerStudent(){
}
}
// 学生类
package com.evan.model;
public class Student {
// 属性
protected String id;
protected String name;
protected int age;
protected float score;
// 行为
public void action(){
}
// 构造函数
public Student(){
}
public Student(String id, String name, int age, float score) {
this.id = id;
this.name = name;
this.age = age;
this.score = score;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public String toString() {
return "id:"+id+",name:"+name+",age:"+age+",score:"+score;
}
}