请帮帮我。我是编程新手。我有一些任务要提交。 我使用Netbeans。我想编辑一个关于给出matric编号的学生的特定数据。首先,系统将提示学生的基础编号。如果找到,系统将询问用户是否要编辑数据(名称或matric或年龄或标记)。用户将指定哪些数据,然后系统将要求用户输入数据的新值。使用新值设置数据后,系统将显示有关学生的所有数据。 这是我的代码:
班级:
公共班学生{
int matric;
String name;
int age;
double mark;
String grade;
Student(int m, String n, int a, double mk) {
matric = m;
name = n;
age = a;
mark = mk;
}
public String computeGrade() {
return "";
}
public String getName() {
return name;
}
public void setName(int name) {
this.matric = name;
}
public int getMatric() {
return matric;
}
public void setMatric(int matric) {
this.matric = matric;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getMark() {
return mark;
}
public void setMark(double mark) {
this.mark = mark;
}
else if (choice == 4) {
System.out.println ("Edit Student Data");
System.out.print("Enter the matric number>");
int matric = read.nextInt();
boolean found=false;
for (int i = 0; i < index; i++) {
if (myStud[i].getMatric() == matric) {
System.out.println("======================================");
System.out.println("Student Name = " + myStud[i].getName());
System.out.println("Student Matric = " + myStud[i].getMatric());
System.out.println("Student Age = " + myStud[i].getAge());
System.out.println("Student Mark = " + myStud[i].getMark());
System.out.println("Student Grade = " + myStud[i].computeGrade());
System.out.println("======================================");
found=true;
System.out.println("1. Edit Name");
System.out.println("2. Edit Matric");
System.out.println("3. Edit Age");
System.out.println("4. Edit Mark");
System.out.print ("Please choose data to edit > ");
int edit = read.nextInt();
if(edit == 1){
System.out.println("Enter Your Name ");
String name = read.next ();
}
else if(edit == 2){
System.out.println("Enter Your Matric ");
matric = read.nextInt ();
}
else if(edit == 3){
System.out.println("Enter Your Age ");
int age = read.nextInt ();
// **how to save and replace the oldest?**
}
else if(edit == 4){
System.out.println("Enter Your Mark ");
int mark = read.nextInt ();
}
System.out.println("Student Data has been updated!");
break;
}
}
if (found==false)
System.out.println("Student Data not Found!");
}
答案 0 :(得分:0)
首先,你有一个数组,而不是ArrayList。你可以这样做:
myStud[i].setAge(readValue);
用于编辑数组中第i个对象的age属性。
这是你要找的答案吗?