我的分配是:
"创建一个跟踪学生特定信息的程序。存储的信息应如下:名字,姓氏,专业,GPA,UIN,NETID,年龄,性别,对于这个简单的程序,我们只需要将10个学生存储在一个数组中。您的学生应存储在一个名为"学生"的对象中。您应该能够在阵列中添加,显示和删除学生。您将提交2个分级文件:lab3driver.java和student.java"
我目前坚持如何使用用户输入来创建所有单独属性的学生对象。
到目前为止我的代码:
public class StudentData{
public static void main(String[] args){
//Creating an info class for the student object
StudentData studentA = new StudentData((strFirstName, strLastName, strMajor,
intGPA, intUIN, strNetID, intAge, strGender));
String strFirstName;
String strLastName;
String strMajor;
int intGPA;
int intUIN;
String strNetID;
String strAge;
String strGender;
StudentData(){
// Capturing user input into class attributes
Scanner input = new Scanner(System.in);
System.out.println("Enter First Name");
strFirstName = input.nextLine();
System.out.println("Enter Last Name");
strLastName = input.nextLine();
System.out.println("Enter Major");
strMajor = input.nextLine();
System.out.println("Enter GPA");
intGPA = input.nextLine();
System.out.println("UIN");
intUIN = input.nextLine();
System.out.println("Enter netID");
strNetID = input.nextLine();
System.out.println("Enter Age");
strAge = input.nextLine();
System.out.println("Enter Gender");
strGender = input.nextLine();
}
创建一个带有变量的类student
:
public class Student {
public String strFirstName;
public String strLastName;
public String strMajor;
public int intGPA;
public int intUIN;
public String strNetID;
public String strAge;
public String strGender;
public static void Student(String strFirstName, String strLastName, String strMajor, int intGPA, int intUIN, String strNetID, String strAge, String strGender) {
this.strFirstName = strFirstName;
this.strLastName = strLastName;
this.strMajor = strMajor;
this.intGPA = intGPA;
this.intUIN = intUIN;
this.strNetID = strNetID;
this.strAge = strAge;
this.strGender = strGender;
}
}
创建一个学生:
Student mystudent = new Student(firstname, lastname, major, GPA, UIN, netID, age, gender);
创建一系列学生:
Student[] myarray = new Student[length];
将学生添加到数组:
myarray[0] = new Student(firstname, lastname, major, GPA, UIN, netID, age, gender);