title: Add, View, Update, and Delete Student Record using Array
body: <p>i need help with my code. I am stuck at 2 (View student record), we only allowed to use arrays and not arraylist or linked list. Any advice and help will do.</p>
  
  <p>Heres the instructions:
  Write a menu driven program that performs the following:</p>
  
  <p>1.Add record
  - can add N students record into the list (ID num, name, course, year)</p>
  
  <p>2.View record
  - can view record by ID number, by course, by course and year
  - or view all</p>
  
  <p>3.Update record
  - can edit/modify the records attribute excluding the ID</p>
  
  <p>4.Delete
  - can remove student record</p>
  
  <p>Heres my code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class StudentArray {
  
  public static void main(String[] args){
  
      getMenu();
  
  }
  public static void getMenu( ){
      Student[] stud = new Student[100];
  
      Scanner sc = new Scanner(System.in);
      int select;
      System.out.println("1. Add Student Record");
      System.out.println("2. View Student Record");
      System.out.println("3. Update Student Record");
      System.out.println("4. Delete Student Record");
      System.out.println("0. Exit");
      select = sc.nextInt();
  
      switch (select){
          case 1:
              addStud(stud);
              getMenu();
              break;
          case 2:
              viewStud(stud);
              getMenu();
              break;
          case 3:
              break;
          case 4:
              break;
          case 0:
              break;
          default:
      }
  
  }
  public static void addStud(Student[] stud){
      Scanner sc = new Scanner(System.in);
       int numID, year;
       String userName, course;
  
      int addMore;
      int i = 0;
      do{
  
          System.out.println("1. Enter Student ID: ");
           numID = sc.nextInt();
          sc.nextLine();
          System.out.println("2. Enter Student Name");
           userName = sc.nextLine();
          System.out.println("3. Enter Student Course");
           course = sc.nextLine();
          System.out.println("4. Enter Student Year");
           year = sc.nextInt();
           stud[i] = new Student(numID, year, userName, course);
          ++i;
  
          System.out.println("To add another Student Record Press 1");
          addMore = sc.nextInt();
      }while (addMore == 1 );
  
  }
  public static void viewStud(Student[] stud){
      for(int x = 0; x &lt; stud.length ; ++x){
          System.out.println("1. Student ID: " + stud[x].getNumID());
          System.out.println("2. Student Name: " + stud[x].getUserName());
          System.out.println("3. Student Course: " + stud[x].getCourse());
          System.out.println("4. Student Year: " + stud[x].getYear() + "\n");
      }
  
  }
  }
  </code></pre>
  
  <p>My Student Class:</p>
  
  <pre><code>public class Student {
  
  private int numID, year;
  private String userName, course;
  
  public Student(int numID, int year, String userName, String course) {
  
      this.numID = numID;
      this.year = year;
      this.userName = userName;
      this.course = course;
  
  }
  
  
  public int getNumID() {
      return numID;
  }
  
  public void setNumID(int numID) {
      this.numID = numID;
  }
  
  public int getYear() {
      return year;
  }
  
  public void setYear(int year) {
      this.year = year;
  }
  
  public String getUserName() {
      return userName;
  }
  
  public void setUserName(String userName) {
      this.userName = userName;
  }
  
  public String getCourse() {
      return course;
  }
  
  public void setCourse(String course) {
      this.course = course;
  }
  
  }
  </code></pre>
  
  <p>Hello thank you SNJ,</p>
  
  <p>I remove my getMenu method and put the code in the main instead.But I'm unable to set the Student array and i to static</p>
  
  <pre><code>import java.util.Scanner;
  </code></pre>
  
  <p>public class StudentArray {</p>
  
  <pre><code>    public static void main(String[] args) {
  
          static Student[] stud = new Student[100];
          static int i = 0;
  
          Scanner sc = new Scanner(System.in);
          while (true) {
  
              int select;
              System.out.println("1. Add Student Record");
              System.out.println("2. View Student Record");
              System.out.println("3. Update Student Record");
              System.out.println("4. Delete Student Record");
              System.out.println("0. Exit");
              select = sc.nextInt();
  
              switch (select) {
                  case 1:
                      addStud(stud);
                      break;
                  case 2:
                      viewStud(stud);
                      break;
                  case 3:
                      break;
                  case 4:
                      break;
                  case 0:
                      return;
                  default:
                      System.out.println("Invalid Option");
              }
          }
  
      }
  
      public static void addStud(Student[] stud) {
          Scanner sc = new Scanner(System.in);
          int numID, year;
          String userName, course;
  
          int addMore;
  
          do {
  
              System.out.println("1. Enter Student ID: ");
              numID = sc.nextInt();
              sc.nextLine();
              System.out.println("2. Enter Student Name");
              userName = sc.nextLine();
              System.out.println("3. Enter Student Course");
              course = sc.nextLine();
              System.out.println("4. Enter Student Year");
              year = sc.nextInt();
              stud[i] = new Student(numID, year, userName, course);
              ++i;
  
              System.out.println("To add another Student Record Press 1");
              addMore = sc.nextInt();
          } while (addMore == 1);
  
      }
  
      public static void viewStud(Student[] stud) {
  
          for (Student element : stud) {
              if (null != element) {
                  System.out.println("1. Student ID: " + element.getNumID());
                  System.out.println("2. Student Name: " + element.getUserName());
                  System.out.println("3. Student Course: " + element.getCourse());
                  System.out.println("4. Student Year: " + element.getYear() + "\n");
              }
          }
  
      }
  </code></pre>