2021年2月5日星期五

public class JavaApplication1 {      public static void main(String[] args) {          Scanner input = new Scanner(System.in);          SignUp cast = new SignUp();          cast.menu();      }  }  class SignUp{      public String[] surname = new String[10];      public String[] name = new String[10];      void register(){          Scanner input = new Scanner(System.in);          System.out.print("How many account would you like to register: ");          int accNo = Integer.parseInt(input.nextLine());          name = new String[accNo];          surname = new String[accNo];          for(int i = 0, j = 0; i<name.length && j<surname.length; i++, j++){              System.out.print("Please enter your first name in ["+(i+1)+"]:");              name[i] = input.nextLine();              System.out.print("Please enter your last name ["+(j+1)+"]:");              surname[j] = input.nextLine();              System.out.println("Successfully registered welcome "+name[i]+" "+surname[i]);          }          menu();      }      void logIn(){          Scanner input = new Scanner(System.in);          String username, password;          boolean flag = false;          System.out.print("Input your username: ");          username = input.nextLine();          System.out.print("Input your password: ");          password = input.nextLine();          for(int i = 0, j = 0; i<name.length && j<name.length; i++, j++){              if(name[i].equals(username) && surname[j].equals(password)){                  flag = true;                  System.out.println("Youve been successfuly loged in");                  System.out.println("Welcome to [frncCorp] : "+name[i]+", "+surname[j]);                  repeater();              }              else if(!name[i].equals(username) && surname[j].equals(password)){                  System.out.println("Invalid username input results to "+flag);                  repeater();              }              else if(name[i].equals(username) && !surname[j].equals(password)){                  System.out.println("Invalid password input results to "+flag);                  repeater();              }          }if(flag == false){              System.out.println("Invalid input! "+flag);              repeater();          }      }      void repeater(){          Scanner input = new Scanner(System.in);          SignUp cast = new SignUp();          String repeat;          System.out.print("Would you like to repeat?[Y/N]: ");          repeat = input.nextLine();          if(repeat == "Y" || repeat == "y"){              cast.logIn();          }          else if(repeat == "N" || repeat == "n"){              System.out.print("Thanks come again :>");              System.exit(0);          }          else{              System.out.print("Invalid input! Try again.");              repeater();          }      }      void menu(){          Scanner input = new Scanner(System.in);          SignUp cast = new SignUp();          int choice;          while(true){              System.out.println("ACCOUNT CREATION SYSTEM");              System.out.println("1. Sign Up: ");              System.out.println("2. Log in: ");              System.out.println("3. Exit: ");              System.out.print("Input choice: ");              choice = input.nextInt();              switch(choice){                  case 1:                       cast.register();                      break;                  case 2:                      cast.logIn();                      break;                  case 3:                      System.exit(0);                      break;                  default:                      System.out.print("Invalid input! Try again.");                      menu();                      break;              }          }      }  }  

*OUTPUT:
ACCOUNT CREATION SYSTEM

  1. Sign Up:
  2. Log in:
  3. Exit:
    Input choice: 1
    How many account would you like to register: 1
    Please enter your first name in [1]:gusion
    Please enter your last name [1]:brief
    Successfully registered welcome gusion brief
    ACCOUNT CREATION SYSTEM
  4. Sign Up:
  5. Log in:
  6. Exit:
    Input choice: 2
    Input your username: gusion
    Input your password: brief
    The error starts when i finished log in then the error occur
    * ERROR GENERATED:
    Exception in thread "main" java.lang.NullPointerException
    at javaapplication1.SignUp.logIn(JavaApplication1.java:38)
    at javaapplication1.SignUp.menu(JavaApplication1.java:91)
    at javaapplication1.SignUp.register(JavaApplication1.java:27)
    at javaapplication1.SignUp.menu(JavaApplication1.java:88)
    at javaapplication1.JavaApplication1.main(JavaApplication1.java:8)
https://stackoverflow.com/questions/66073381/can-anyone-help-me-i-do-not-know-where-the-error-is-coming-from February 06, 2021 at 11:47AM

没有评论:

发表评论