Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我需要创建一个程序,在创建的学生、本科生和研究生班级中添加、删除、列出、保存和排序学生_Java - Fatal编程技术网

Java 我需要创建一个程序,在创建的学生、本科生和研究生班级中添加、删除、列出、保存和排序学生

Java 我需要创建一个程序,在创建的学生、本科生和研究生班级中添加、删除、列出、保存和排序学生,java,Java,我有三个不同的班,一个是研究生班,一个是本科生班,然后是普通学生班,我需要找出如何从main方法将学生添加到数组列表中。我不知道如何添加名字,因为它是私有的,需要保持私有 package enrollmentdatabase; import java.util.ArrayList; import java.util.Scanner; public class EnrollmentDataBase { public static void main(String[] args) {

我有三个不同的班,一个是研究生班,一个是本科生班,然后是普通学生班,我需要找出如何从main方法将学生添加到数组列表中。我不知道如何添加名字,因为它是私有的,需要保持私有

package enrollmentdatabase;

import java.util.ArrayList;
import java.util.Scanner;

public class EnrollmentDataBase {

public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
    String option = optionChoise(input);
    String option1 = "ADD";//ADD option
    String option2 = "REMOVE";//REMOVE OPTION
    String option3 = "LIST";//LIST OPTION
    String option4 = "SAVE";//SAVE OPTION
    String option5 = "SORT";//SORT OPTION
    ArrayList studentList = new ArrayList();

}//end of main method
public static String optionChoise(Scanner input){
    String opt1 = "ADD";//ADD option
    String opt2 = "REMOVE";//REMOVE OPTION
    String opt3 = "LIST";//LIST OPTION
    String opt4 = "SAVE";//SAVE OPTION
    String opt5 = "SORT";//SORT OPTION
    System.out.println("Enter what you want to do(ADD, REMOVE, LIST, SAVE, or SORT): ");
    String opt = input.nextLine();
    if((opt.compareToIgnoreCase(opt1)) !=0 || (opt.compareToIgnoreCase(opt1)) != 0 || (opt.compareToIgnoreCase(opt1)) !=0
            || (opt.compareToIgnoreCase(opt1)) !=0 || (opt.compareToIgnoreCase(opt1)) !=0){//enter this if conditional in order to establish that the input is valid
        System.out.println("This is not a valid input, please enter in what you want to do: ");
        opt = input.nextLine();
    }//end of if conditional
    return opt;
}//end of option method
public static ArrayList addList(ArrayList studentList, Scanner input){
    System.out.println("Enter the Student's first name: ");
    String nameFirst= input.nextLine();
    Student student1 = new Student();
    student1.firstName = nameFirst;
    System.out.println("Enter the Student's last name: ");
    System.out.println("Enter the Student's UID: ");
    System.out.println("Enter the Student's status: ");
    System.out.println("Enter YES for having a thesis option, else NO: ");
    System.out.println("Enter Masters for Master Studies of PHD for PHD studies: ");
    System.out.println("Enter the name of the major professor: ");
    System.out.println("Enter the student class standing: ");
    System.out.println("Enter the Student's major: ");
    System.out.println("Enter the student's overall GPA: ");
    System.out.println("Enter the student's major GPA: ");
}//end of addList method
}//end of class
我不知道如何添加名字,因为它是私有的

拥有用于私有数据的公共getter公共setter方法,并通过它们进行访问

例如:

    class Student {
    private String fName;
    public void setFname(String fName){
    this.fName = fName;
    }
    public String getFName(){
    return fname;
    }
    }
class AnotherClass {
public static void main(String...args){
student s = new Student();
System.out.println(s.getFName());//to access fName(which is private) in class Student.
}

}

天哪。。。?你在发明数据库?@BlueBullet。。我会说“制造数据库”。;)在直接进入ArrayList之前,请阅读优秀的Java书籍并编写基本代码。你可以从一开始。因为,即使有人给你一个方法,这对你也没有好处。不能区分修饰语吗?