時,字符串不會顯示我有一個問題,即使輸入了信息,當被調用顯示時(選項6),它也不會顯示從選項6輸入的信息。我覺得它是因爲我不能顯示在我的courseModule類中添加super(courseName)。任何幫助,不勝感激,虐待留下所有相關的代碼。當調用
AppMain類
import java.util.*;
public class AppMain {
// ArrayList of students
private static ArrayList<Student> studentList = new ArrayList<Student>();
// ArrayList of teachers
private static ArrayList<Teacher> teacherList = new ArrayList<Teacher>();
// ArrayList of Modules
private static ArrayList<CourseModule> ModuleList = new ArrayList<CourseModule>();
public static void main(String[] args)
{
menu();
}
public static void menu()
{
int option = 0;
while(option != 7) {
Scanner in = new Scanner(System.in);
// Creates main menu
System.out.println("Choose an option.");
System.out.println("[1] Create student");
System.out.println("[2] Display students");
System.out.println("[3] Create Teacher");
System.out.println("[4] Display Teachers");
System.out.println("[5] Create Module");
System.out.println("[6] Display Modules");
System.out.println("[7] Exit");
System.out.print("Option? ");
option = in.nextInt();
// Switch case for dealing with choice
// Each case is braced {} so convinient variable names can be reused..
// .. without fear of variables 'carrying over'
switch (option) {
case 1: {
String name;
int grade;
System.out.println("Enter name: ");
in.nextLine(); // Stops the program 'running' over the next line
name = in.nextLine();
System.out.println("Enter grade: ");
grade = in.nextInt();
if (grade <= 100 && grade >= 0) {
Student student = new Student(name, grade);
studentList.add(student);
//error message
} else {
System.out.println("Grade not in boundaries!\nUser not added \nEnter grade between 0-100.");
}
break;
}
case 2: {
Iterator<Student> itr = studentList.iterator();
while (itr.hasNext()) {
Student student = itr.next();
System.out.println(student.toString() + "\n");
}
break;
}
case 3: {
String name;
System.out.println("Enter Teachers name: ");
in.nextLine();
name = in.nextLine();
Teacher teacher = new Teacher(name);
teacherList.add(teacher);
break;
}
case 4: {
// Iterators through the teachList ArrayList..
// .. and prints each one with a line between
Iterator<Teacher> itr = teacherList.iterator();
while (itr.hasNext()) {
Teacher teacher = itr.next();
System.out.println(teacher.toString() + "\n");
}
break;
}
case 5: {
String name;
String courseName; // defining module String
System.out.println("Enter Teachers name: ");
in.nextLine();
name = in.nextLine();
Teacher teacher = new Teacher(name);
teacherList.add(teacher);
System.out.println("Enter Module Name: ");
courseName = in.nextLine();
CourseModule Module = new CourseModule(courseName, teacher);
ModuleList.add(Module);
break;
}
case 6: {
// Iterator<Teacher> itr = teacherList.iterator();
// while (itr.hasNext()) {
// Teacher teacher = itr.next();
// System.out.println(teacher.toString() + "\n");
// }
Iterator<CourseModule> itr = ModuleList.iterator();
while (itr.hasNext()) {
CourseModule Module = itr.next();
System.out.println(Module.toString() + "\n");
}
而且繼承人的CourseModule類
import java.util.*;
public class CourseModule implements Course {
String courseName;
Teacher teacher;
ArrayList<Student> students = new ArrayList<Student>();
public CourseModule (String courseName, Teacher teacher) {
}
@Override
public void assignTeacher(Teacher teacher) {
}
@Override
public void enrolStudent(Student student) {
}
我有一種感覺它做的courseModule公共courseModule但一切我都試過不行的,任何幫助非常感謝卡住了30分鐘,發現其他地方沒有幫助
這是一個家庭作業?如果是的話,請將作業標籤 – FrankK
包括在我的一個Uni工作室的作業中,只是看到了你的編輯,不知道這是一件現在會做的事 –
好,那麼,它不顯示「[6]顯示模塊「部分,或者外殼6下的部分:? – FrankK