1、 创建接口Introduce,包含introduce方法;
2、 创建类Person,包含姓名,实现Introduce接口;
3、 创建类Student、Teacher 继承Person,重写introduce方法;
Student包含学号,Teacher包含职称;
4、 随机初始化姓名、学号、职称等信息,
姓名:包含5个字母,首字母大写;
学好:整数,随机6位数;
职称:随机从 lecturer、professor、associate选择。
5、 创建带main方法的类,分别产生5位教师和100位学生,并作介绍。
6、 创建多线程,假设有1000道题,由以上5位老师依次将题分配给随机抽取的某个学生,每位老师一个线程。
7、 将分发结果保存到文件。
public interface Introduce{
void introduce();
}
public class Person implements Introduce{
String name;
public void introduce(){
System.out.println("我是:"+name);
}
}
import java.util.*;
public class Student extends Person{
int studId;
public Student(String name){
super(name);
Random rnd = Random();
this.studId = rnd.nextInt(899999)+100000;
}
public void introduce(){
System.out.println("我是:"+name);
}
}
public class Teacher extends Person{
String job;
String arr[] = {"lecturer","professor","associate"};
public Teacher (String name){
super(name);
Random rnd = Random();
job = arr[rnd.nextInt(3)];
}
public void introduce(){
System.out.println("我是:"+name);
}
}
问题不难但是需求多,主要用到接口和类,后面还有随机数和线程
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632