i am trying to insert 5 students ids and a
course number for each student id. Then it prints all
5 student ids and the course name associated with
each student id.
but im having trouble with inserting the main method because i have no idea what to input.
package assignment10; import java.util.Scanner; public class BannerWebArray { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int studentId,courseId,i; String courseName; BannerUser[] bannerUser=new BannerUser[5]; for (i=0;i<5;i++) bannerUser[i]=new BannerUser(); for (i=0;i<5;i++) { System.out.print("Enter student id:"); studentId=scan.nextInt(); System.out.print("Enter course id: 1 for Math, 2 for English"); courseId=scan.nextInt(); bannerUser[i].setUserId(studentId); courseName=bannerUser[i].register(courseId); bannerUser[i].setCourseName(courseName); System.out.println("Students registered for Math:"); for (i=0;i<5;i++) { courseName=bannerUser[i].getcourseName(); if (courseName.equals("Math")) System.out.println(bannerUser[i].getUserId()); } System.out.println("Student registered for English"); for (i=0;i<5;i++) { courseName=bannerUser[i].getcourseName(); if (courseName.equals("English")) System.out.println(bannerUser[i].getUserId()); } } } }
error message:
Enter student id:12345
Enter course id: 1 for Math, 2 for English2
Students registered for Math:
Exception in thread "main" java.lang.NullPointerException
at assignment10.BannerWebArray.main(BannerWebArray.ja va:33)