Java 询问非原语arraylist

Java 询问非原语arraylist,java,arrays,oop,arraylist,Java,Arrays,Oop,Arraylist,我已经创建了ArrayList。如何使用此列表从类中获取方法或属性。我试过了,但没有找到任何解决办法 我试图进入数组列表中的元素并获得一些属性,但我做不到 public static void printOptions() { System.out.println("Welcome to our university!"); System.out.println("Operations:"); System.out.println("1- College");Sy

我已经创建了
ArrayList
。如何使用此列表从类中获取方法或属性。我试过了,但没有找到任何解决办法

我试图进入数组列表中的元素并获得一些属性,但我做不到

    public static void printOptions() {
    System.out.println("Welcome to our university!");
    System.out.println("Operations:");
    System.out.println("1- College");System.out.println("a) Number of Departments");System.out.println("b) Number of Courses");System.out.println("c) Number of Professors");System.out.println("d) Number of Students");System.out.println("e) Report");
    System.out.println("2- Department");System.out.println("a) New");System.out.println("b) Number of Courses");System.out.println("c) Number of Students");System.out.println("d) Is Full");System.out.println("e) Enroll");System.out.println("f) Report");
    System.out.println("3- Course");System.out.println("a) New");System.out.println("b) Number of Students");System.out.println("c) Assign");System.out.println("d) Is assigned");System.out.println("e) Professor Name");System.out.println("f) Is Full");System.out.println("g) Enroll");System.out.println("h) Report");
    System.out.println("4- Professor");System.out.println("a) New");System.out.println("b) Display Salary");System.out.println("c) Get Raise");System.out.println("d) Report");
    System.out.println("5- Student");System.out.println("a) New");System.out.println("b) Report");
    System.out.println("6- Quit");
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here

    printOptions() ;
      List<Department> departmentList;departmentList = new ArrayList<>();
      List<Course> courseList ;courseList = new ArrayList<>();
      List<Professor> proffList = new ArrayList<>() ;
      List<Student> studentList;studentList = new ArrayList<>() ;



      Scanner in = new Scanner(System.in) ; 
    int d = 0 , c = 0  , p = 0 , s=0 ; 
    College AinShams = new College() ; 
    while (true){

        String option = in.nextLine() ; 
        if(!"6".equals(option)) {
            if ("2a".equals(option)) { // Define new department
                System.out.println("Department Name:");
                String depName = in.nextLine() ; 
                System.out.println("Department Description:");
                String depDescripe = in.nextLine() ;
                System.out.println("Department Max Students:");
                int max_num = in.nextInt() ;
                in.nextLine() ; 
                Department Department_Name = new Department(depName, depDescripe, max_num); 

               //  departmentList.add(Department_Name);
                 departmentList.add(d, Department_Name);
                d++ ;
                AinShams.setDepart(departmentList);

            }

            else if ("4a".equalsIgnoreCase(option)) {//new proff
                System.out.println("Professor Firstname:");
                String firstName = in.nextLine() ;
                System.out.println("Professor Lastname:");
                String lastName = in.nextLine(); 
                System.out.println("Professor telephone:");
                String telephone = in.nextLine();
                System.out.println("Professor address:");
                String address = in.nextLine();
                System.out.println("Professor salary:");
                double salary = in.nextDouble() ;
                Professor proff = new Professor(firstName, lastName, telephone, address, salary); 
                proffList.add(p,proff) ;
                p++ ; 
                AinShams.setProf(proffList);
               }

            else if ("2e".equalsIgnoreCase(option)) {//add student in department
                System.out.println("Department:");
                String dep= in.nextLine() ;
                System.out.println("Student:");
                String stu= in.nextLine();   

              //  System.out.println(AinShams.getDepart());
              AinShams.getDepart().
                /*for (int i = 0; i < AinShams.getDepart().size(); i++) {
        }*/
            }
            System.out.println("============");
            System.out.println("Enter Operation");
            System.out.println("============");
        }else {break ;}


    }

}

}
publicstaticvoidprintpoptions(){
System.out.println(“欢迎来到我们大学!”);
System.out.println(“操作:”);
系统输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出;
系统输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出;
系统输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出输出;
System.out.println(“4-Professor”);System.out.println(“a)New”);System.out.println(“b)Display Salary”);System.out.println(“c)Get Raise”);System.out.println(“d)Report);
System.out.println(“5-学生”);System.out.println(“a)新”);System.out.println(“b)报告);
System.out.println(“6-退出”);
}
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
//此处的TODO代码应用程序逻辑
打印选项();
列出部门列表;部门列表=新建ArrayList();
列出courseList;courseList=new ArrayList();
List proffList=new ArrayList();
List studentList;studentList=newarraylist();
扫描仪输入=新扫描仪(系统输入);
int d=0,c=0,p=0,s=0;
学院=新学院();
while(true){
字符串选项=in.nextLine();
如果(!“6”。等于(选项)){
如果(“2a”.equals(选项)){//定义新部门
System.out.println(“部门名称:”);
字符串depName=in.nextLine();
System.out.println(“部门描述:”);
字符串depsdescripe=in.nextLine();
System.out.println(“部门最大学生:”);
int max_num=in.nextInt();
in.nextLine();
部门名称=新部门(部门名称、部门描述、最大数量);
//部门列表。添加(部门名称);
部门列表。添加(d,部门名称);
d++;
AinShams.SetDeeption(部门列表);
}
else if(“4a”.equalsIgnoreCase(选项)){//new proff
System.out.println(“教授名:”);
String firstName=in.nextLine();
System.out.println(“教授姓氏:”);
字符串lastName=in.nextLine();
System.out.println(“教授电话:”);
字符串电话=in.nextLine();
System.out.println(“教授地址:”);
字符串地址=in.nextLine();
System.out.println(“教授工资:”);
双倍工资=in.nextDouble();
Professor proff=新教授(名、姓、电话、地址、薪水);
proffList.add(p,proff);
p++;
AinShams.setProf(proffList);
}
else if(“2e”.equalsIgnoreCase(选项)){//在系中添加学生
System.out.println(“部门:”);
字符串dep=in.nextLine();
System.out.println(“学生:”);
字符串stu=in.nextLine();
//System.out.println(AinShams.getDepart());
AinShams.getDepart()。
/*对于(int i=0;i
在条件(2e)中,我需要获取我在数组列表中指定的类中的方法和属性。getDeep()指的是您定义为数据类型的对象:

College AinShams = new College(); 
学院代码的其余部分不在此片段中,因此我无法判断.getDevement()方法是否存在。不管怎样,该学院都不是一个ArrayList

如果要访问ArrayList中对象的方法和字段,可以使用以下方法。例如,我使用名为departmentlist的ArrayList,并使用get()方法从该列表返回第0个元素。假设该类的第0个元素是Department类型的对象,.name要求输入name字段(同样,假设Department类中存在此name变量)。.getName()是获取名称值的更好方法,但需要在Department类中编码此方法

departmentlist.get(0).name
departmentlist.get(0).getName()
顺便说一下,通过用“\n”新行键格式化输出,考虑在代码顶部减少一些“Soal.Out.PrtLnf())杂波。使用1 system.out.println调用打印两行文本,尝试以下两个示例:

System.out.println("Welcome to our university!" + "\n" + "Operations:");
System.out.println("Welcome to our university! \nOperations:");
AinShams.getDeep()引用的是您定义为数据类型的对象:

College AinShams = new College(); 
学院代码的其余部分不在此片段中,因此我无法判断.getDevement()方法是否存在。不管怎样,该学院都不是一个ArrayList

如果要访问ArrayList中对象的方法和字段,可以使用以下方法。例如,我使用名为departmentlist的ArrayList,并使用get()方法从该列表返回第0个元素。假设0
Department findDepartment(List<Department> deptList, String dept) {
    for(Department department : deptList) {
        if(department.getName().equals(dept)) {
            return department;
        }
    }
    return null;
}