班级注册是大学生的一个重要方面。注册课程时,您必须知道课程编号(CRN)。
下表列出了一些CRN及其相应的课程标题。
CRN | COURSE TITLE
12451 | Introduction to IT Problem Solving Using Computer Programming
15349 | Object-Oriented Techniques for IT Problem Solving
18467 | Applied IT Programming
16890 | Database Fundamentals
13334 | Database Programming
我需要创建一个程序来让学生注册这些课程。当用户输入CRN时,会发生一次课程注册。在注册服务商(用户)指示他们已完成输入CRN之前,继续提示用户输入CRN。您必须验证CRN,提供错误消息,并在输入无效CRN时重新提示用户。跟踪每门课程的入学人数。特定CRN的课程注册不能超过其最大注册,否则将显示错误消息,并且不会处理注册。
一旦用户表示他们已完成输入CRN,显示格式正确的报告,其中包含每个课程的列表及其CRN和标题,注册的学生人数以及剩余的座位数。
运行代码后, 1.退出最初几次都没有做任何事情 我还没弄明白如何忽略重叠输入 3.我需要将限制设置为30
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
class TwoD
{
private static boolean typeInt(String a) throws IOException {
try {
Integer.parseInt(a);
return true;
} catch (NumberFormatException e) {
return false;
}
}
public static void main(String[] args) throws IOException
{
{
System.out.println("These are the courses that you can choose for the students to enroll. \n 12451 | Introduction to IT Problem Solving Using Computer Programming \n 15349 | Object-Oriented Techniques for IT Problem Solving \n 18467 | Applied IT Programming \n 16890 | Database Fundamentals \n 13334 | Database Programming");
ArrayList<String> name = new ArrayList<String>();
Scanner scan = new Scanner(System.in);
System.out.print("What is your student's name? ");
String student = scan.next();
String a;
while(!student.equalsIgnoreCase("quit")) {
name.add(student); //after a cycle of while, ask user whether he or she would quit and print the arraylist of students.
System.out.print("What is your student's name? ");
student = scan.next();
}
ArrayList< ArrayList<String> > main = new ArrayList< ArrayList<String> >();
for(int i = 0; i<name.size(); i++){
ArrayList<String> course = new ArrayList<String>();
for (int j = 0; j < name.size(); j++){
System.out.print("The course the student is currently enrolling is : ");
a = scan.next();
while (!a.equalsIgnoreCase("quit"))
{
while(!typeInt(a) || Integer.parseInt(a) != 12451 && Integer.parseInt(a) != 15349 && Integer.parseInt(a) != 16890 && Integer.parseInt(a) != 13334 && Integer.parseInt(a) != 18467) {
System.out.println("Check the courses again.");
a = scan.next();
}
course.add(a);
if (a.equalsIgnoreCase("quit")!=true)
{
System.out.print("The course the student is currently enrolling is : ");
a = scan.next();
}
else break;
}
}
main.add(course);
}
for(int i = 0; i < name.size(); i++){
System.out.print("Name " + i + ": ");
for(int j = 0; j < main.get(i).size(); j++){
System.out.print(main.get(i).get(j) + " ");
}
System.out.println();
}
}
}
}
答案 0 :(得分:0)
这是一个关于如何调试的教程的链接。我过去花了几个小时试图弄清楚我的代码出了什么问题,并在网上寻找答案。最后,我必须知道我的最终项目在截止日期前两小时没有工作。
这项技能将为您提供良好的服务,并在您的职业生涯中为您节省数百小时。