public abstract class Course {
/**
* 课程名称
*/
private String name;
/**
* 课时
*/
private int count;
/**
* 课程类型
*/
private String type;
/**
* 课程内容
*/
private CourseContent[] content;
public Course() {
}
public Course(String name, int count, String type, CourseContent[] content) {
this.name = name;
this.count = count;
this.type = type;
this.content = content;
}
public abstract void study();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public CourseContent[] getContent() {
return content;
}
public void setContent(CourseContent[] content) {
this.content = content;
}
public interface CourseContent {
void doStudy();
}
public static class JavaCourse extends Course {
public JavaCourse() {
}
public JavaCourse(String name, int count, String type, CourseContent[] content) {
super(name, count, type, content);
}
@Override
public void study() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入需要学习的内容:");
int i = scanner.nextInt();
if (i < 0 || i >= getContent().length) {
System.out.println("暂时没有该学习内容!");
return;
}
getContent()[i].doStudy();
}
}
public static void main(String[] args) {
JavaCourse javaCourse = new JavaCourse("Java", 20, "专业基础", new CourseContent[]{new CourseContent() {
@Override
public void doStudy() {
System.out.println("冒泡排序");
}
}, new CourseContent() {
@Override
public void doStudy() {
System.out.println("剪刀石头布");
}
}, new CourseContent() {
@Override
public void doStudy() {
System.out.println("抽取幸运观众");
}
}});
javaCourse.study();
}
}