public class BannerUser
{
private int [] userId = new int[20];
private int [] courseNumber = new int[20];
private final String [] courseName={"Math" , "History", "English", "Art", "Science"};
public int getUserId() {
int [] tempUser = new int[userId.length];
for (int i = 0; i < userId.length; i++)
{
tempUser[i]=userId[i];
}
return tempUser;
}
public void setUserId(int userId) {
for (int i = 0; i < 20; i++)
this.userId[i]=userId;
}
public void displayCourses() {
for (int i=0; i < courseName.length; i++){
courseNumber[i]=i + 1;
System.out.println(courseNumber[i] +"\t"+ courseName[i]);
}
}
public void registration (int courseNumber){
if (courseNumber < courseName.length)
{
for (int i=0; i < 20; i++)
{
this.courseNumber[i]=courseNumber;
}
}
public void displayArrays()
{
System.out.println("Student ID\tCourseNumber");
for (int row=0;row<userId.length;row++){
System.out.print(userId[row] +"\t"+ courseNumber[row]);}
}
}
import java.util.Scanner;
import javax.swing.JOptionPane;
public class BannerUserClient {
public static void main (String[] args) {
BannerUser bannerUser = new BannerUser();
Scanner scan=new Scanner(System.in);
boolean done=false;
int userType;
int userId;
int courseNumber;
//int [] userId = new int[20];
for (int i =0;i<20;i++)
{
System.out.println("Enter user ID:");
userId=scan.nextInt();
bannerUser.setUserId(userId);
do{
System.out.println("enter\n(1) for faculty services\n(2) for student services:");
userType=scan.nextInt();
if (userType==1) {
System.out.println("Under Construction");
System.exit(0);
}
else if (userType==2) {
done=true;
bannerUser.displayCourses();
System.out.println("Enter a course number");
courseNumber=scan.nextInt();
bannerUser.registration(courseNumber);
//bannerUser.
}
else
//System.out.println("invalid input!");
bannerUser.displayArrays();
} while(!done);
}
}
}
抱歉,如果这看起来很糟糕。基本上,我正在学习我学校的编程课程介绍,并且在过去的几个单元中我一直被困住。对于这个项目,我必须创建两个单独的类:私有和公共。我需要从用户那里获取 20 次输入来分配学生 ID 并更新数组 userId。输入 ID 后,他们需要从 5 个不同的选项中选择一个班级。他们选择的课程应该更新数组 courseNumber。毕竟,我需要同时显示 userId 和 courseNumber 值。数组最后不打印,我什至不确定数组是否正在更新。任何帮助将不胜感激。谢谢!