我有一个时间表项目,其中包含 Lecturer 和 Subject 两个类,还指定了已知对象。
并且它们都必须在对象数组或数组列表中
并且该项目应该允许用户能够创建或添加、删除、搜索和更新班级讲师的对象。
我真的不知道该怎么做我可以创建一个可以完成上述任务的方法,它应该是类方法还是主类中的方法?
如何让用户能够使用方法或任何其他方式创建对象?
我已经创建了类、对象和数组列表被卡住了
对不起,我也可以将用户创建的对象添加到数组列表中吗?
class Lecturer {
static int lec_id;
static String lec_name;
static String lec_rank;
static int lec_salary;
static String lec_department;
}
class Subject { /* initialisation for the class subject*/
String sub_code;
String sub_name;
String sub_department;
int sub_lec_id; /*sub lec id represent the lecturer taking the subject*/
String sub_day;
String sub_time;
String sub_venue;
}
/* intialisation for the class lecturer*/
public class Timetable {
public static void main(String[] args) {
/* the code below represent a created list of objects */ /* `Lecturer l =Lecturer ()(System.in);*/`
Lecturer l1 =new Lecturer (1, "Dadson", "Dr", 8000, "Computing");
Lecturer l2 =new Lecturer (2, "Hall", "Prof", 12000, "Computing");
Lecturer l3 =new Lecturer (2, "Berry", "Dr", 7500, "Computing");
Lecturer l4 =new Lecturer (2, "Bull", "Dr", 9000, "Engineering");
Lecturer l5 =new Lecturer (2, "Viles", "Prof", 13500, "Engineering");
Lecturer l6 =new Lecturer (2, "Dyson", "Dr", 7200, "Engineering");
/*The code below represent the array list holding objects of the class Lecturer*/
List<Lecturer> L=new ArrayList<Lecturer>();
L.add(l1);
L.add(l2);
L.add(l3);
L.add(l4);
L.add(l5);
L.add(l6);
/* the code below is to create the object for the class Subject*/
Subject s1=new Subject ("EC3000", "Computing Basics", "Computing", 1, "Mon", "8-10am", "S310");
Subject s2=new Subject ("EE3000", "Engineering Basics", "Engineering", 2, "Tuesday", "10-12pm", "S310");
Subject s3=new Subject ("EC3100", "Programming Fundamentals", "Engineering", 1, "Monday", "1-3pm", "S203");
Subject s4=new Subject ("EE3100", "Engineeering Math", "Computing", 4, "Thursday", "3-5pm", "s420");
Subject s5=new Subject ("EC3200", "Problem Solving", "Computing", 3, "Friday", "8-10pm", "S208");
Subject s6=new Subject ("EE3200", "Circuit", "Enginerring", 4, "Monday", "10-12pm", "S104");
Subject s7=new Subject ("EC3300", "Networking", "Computing", 2, "Tuesday", "1-3pm", "S310");
Subject s8=new Subject ("EE3300", "Electromagnetic", "Engineering", 5, "Wednesday","1-3pm", "S330");
Subject s9=new Subject ("EC3400", "Project", "Computing", 3, "Thursday", "3-5pm", "S312");
Subject s10 =new Subject("EE3400", "Project", "Engineering", 6, "Tuesday", "10-12pm", "S415");
/*The code below represent the array list holding objects of the class Subject*/
Subject[]S=new Subject[10];
S[0]=s1;
S[1]=s2;
S[2]=s3;
S[3]=s4;
S[4]=s5;
S[5]=s6;
S[6]=s7;
S[7]=s8;
S[8]=s9;
S[9]=s10;
}
}