我目前正在努力修复代码的结果。
我应该从菜单添加一个列表,然后显示该列表。但是,我无法检索其内容,而是收到其内存值(我猜?)。
学生班
private int number;
private String author;
private String title;
public Student() {
}
public Student(int number, String title, String author) {
this.number = number;
this.title = title;
this.author = author;
}
public int getNumber() {
return number;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public void setNumber(int number) {
this.number = number;
}
public void setTitle(String title) {
this.title = title;
}
public void setAuthor(String author) {
this.author = author;
}
public String ToString() {
return "Number: " + number + "\tTitle: " + title + "\tAuthor: " + author;
}
主班
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Student> newStudents = new ArrayList<Student>();
System.out.println("Please select a number from the options below \n");
while (true) {
// Give the user a list of their options
System.out.println("1: Add a student to the list.");
System.out.println("2: Remove a student from the list.");
System.out.println("3: Display all students in the list.");
// Get the user input
int userChoice = input.nextInt();
switch (userChoice) {
case 1:
addStudents(newStudents);
break;
case 2:
//removeStudent(newStudents);
break;
case 3:
displayStudent(newStudents);
break;
}
}
}
输出:
1:将学生添加到列表中。
2:从列表中删除学生。
3:显示列表中的所有学生。
3
学生@6b2acb7a
为什么@6b2babc7a?
感谢您的善意帮助和关注。我对编程还算陌生,Java 是我的第一语言。因此,我非常感谢您的帮助和澄清。
富国沪深
慕容森
相关分类