Q:

Create multiple students and check if any are repeated java

In my code I am to input multiple students and have a method check to see if any of the students are repeated (by checking ID number) but I cant seem to be able to set multiple students with my current code and save them. From my current code is there any way to be able to set multiple students or will I have to change my code completely
import java.util.Scanner;
    public class Registrar 
    {

    public static void main(String[] args)
    {

  Scanner input = new Scanner(System.in);

  String string1 = " ";

  while(string1 != "1")
  {

     System.out.println("Please input full name name of student: ");
     string1 = input.next(); // user input of name
     if (string1 != "0"){
        break;
     }
     System.out.println("Please input Student ID (if done enter 0): ");
     String string2 = input.next(); // user input of ID
     System.out.println("Please input Students Credits: ");
     int inputCredits = input.nextInt(); // User input of Credits
     System.out.println("Please input Student's Total Grade Points Earned: ");
     double getPoints = input.nextDouble();
     double GPA = getPoints/inputCredits; //User input of Grade Points Earned and Divide by Credits to get GPA

     Student first = new Student(string1, string2, inputCredits, GPA);

     System.out.println( "Name: " + first.getName() + "\nUser ID: " + first.getId() + "\nCredits: " + first.getCredits() + "\nGrade Point Average: " + first.getGradePoints()  );

     }

  }
}

This is my Student Class
public class Student {  
   private String name;
   private String idnum;
   private int credits;
   private double gradePoints;

   public Student(String n, String id, int c, double gp){
      name = n;
      idnum = id;
      credits = c;
      gradePoints = gp;
      }

   public String getName(){
      return name;
      }
   public String getId(){
      return idnum;
      }
   public int getCredits(){
      return credits;
      }
   public double getGradePoints(){
      return gradePoints;
      }
}

A:

Try this code. better implementation with collection.
      Scanner input = new Scanner(System.in);
      String string1 = " ";
      System.out.println("Number of students to be entered");
      int s = input.nextInt();
      List<Student> studentList = new ArrayList<Student>();

      for(int i = 0; i<s; i++) {
             System.out.println("Please input full name of student: ");
             string1 = input.next(); // user input of name
             System.out.println("Please input Student ID (if done enter 0): ");
             String string2 = input.next(); // user input of ID
             System.out.println("Please input Students Credits: ");
             int inputCredits = input.nextInt(); // User input of Credits
             System.out.println("Please input Student's Total Grade Points Earned: ");
             double getPoints = input.nextDouble();
             double GPA = getPoints/inputCredits; //User input of Grade Points Earned and Divide by Credits to get GPA

             Student student = new Student(string1, string2, inputCredits, GPA);
             System.out.println( "Name: " + first.getName() + "\nUser ID: " + first.getId() + "\nCredits: " + first.getCredits() + "\nGrade Point Average: " + first.getGradePoints()  );
             studentList.add(student);
       }

