import java.util.LinkedList;
import java.util.Scanner;
public class Enrollment {
public static void main(String[] args) {
LinkedList<Student> studentData = new LinkedList<Student>();
LinkedList<Faculty> facultyData = new LinkedList<Faculty>();
LinkedList<Course> courseData = new LinkedList<Course>();
Scanner input = new Scanner(System.in);
System.out.println("Enter 1 to add a student, 2 to add a faculty, 3 to add a course");
int userChoice = input.nextInt();
input.nextLine();
switch (userChoice) {
case 1:
System.out.println("Enter student full name ");
String sName = input.nextLine();
System.out.println("Enter student age ");
int sAge = input.nextInt();
System.out.println("Enter student id ");
int sID = input.nextInt();
input.nextLine();
System.out.println("Enter student address(only address number and street name) ");
String sAddress = input.nextLine();
System.out.println("Enter city, state, and zip code ");
String sCityStateZip = input.nextLine();
System.out.println("Enter student gender ");
String sGender = input.nextLine();
Student studentInfo = new Student(sName, sAge, sID, sAddress, sCityStateZip, sGender);
studentData.add(studentInfo);
for (Student testClass : studentData) {
System.out.println(testClass);
}
break;
case 2:
// code to add faculty
System.out.println("Enter faculty name ");
String fName = input.nextLine();
System.out.println("Enter faculty age ");
int fAge = input.nextInt();
System.out.println("Enter faculty id ");
int fID = input.nextInt();
input.nextLine();
System.out.println("Enter faculty degree ");
String fDegree = input.nextLine();
System.out.println("Enter faculty major ");
String fMajor = input.nextLine();
System.out.println("Enter faculty address ");
String fAddress = input.nextLine();
System.out.println("Enter faculty gender ");
String fGender = input.nextLine();
Faculty facultyInfo = new Faculty(fName, fAge, fID, fDegree, fMajor, fAddress, fGender);
facultyData.add(facultyInfo);
for (Faculty testClass : facultyData) {
System.out.println(testClass);
}
break;
case 3:
// code to add course
System.out.println("Enter course name ");
String courseName = input.nextLine();
System.out.println("Enter course ID ");
int cID = input.nextInt();
System.out.println("Enter number of credits ");
int numOfCred = input.nextInt();
System.out.println("Enter intstructor/faculty ID ");
int instructorID = input.nextInt();
System.out.println("Enter course year ");
int year = input.nextInt();
input.nextLine();
System.out.println("Enter semester ");
String semester = input.nextLine();
System.out.println("Enter classroom size ");
int size = input.nextInt();
System.out.println("Enter course capacity ");
int capacity = input.nextInt();
Course courseInfo = new Course(courseName, cID, numOfCred, instructorID, year, semester, size, capacity);
courseData.add(courseInfo);
for (Course testClass : courseData) {
System.out.println(testClass);
}
break;
default:
System.out.println("Invalid entry");
break;
}
}
登録システムを作成しようとしています。今、私はプログラムを作って、学生が教職員やコースを追加するかどうかを選択するよう促します。ユーザーがオプションを選択して質問された質問に記入すると、プログラムは終了します。ユーザーが質問に答えると、最初のプロンプトに戻り、3つの選択肢が与えられます。switch文のループを作成する方法は?
は、whileループを使用してください。パラメータとして 'true'を使うことができ、無期限にループします。ユーザ要求に応じて終了するには、ユーザ入力に基づいてパラメータをブール値に設定します(「終了しますか?(y/n)」のようなプロンプトが表示されます) – ChickenFeet
改行ラベル。ちょうどgotoのように –
あなたは方法についてまだ教わったことがありますか? –