-2

Ok so a user types in an value for a variable named email in a signup process, then another method is called for them to sign in. When they sign in they have to use the same email they signed up with. Heres my code:

public static void signup() {
  String email;

  System.out.println("Please type in an email");
  Scanner input = new Scanner(System.in);
  email = input.nextLine();
   signin();
}

 public static void signin() {
   String emailForSignin;

   System.out.println("Please sign in with your email");
   Scanner input = new Scanner(System.in);
   emailForSignIn = input.nextLine();
   if (emailForSignin != email) {
     System.out.print("Thats not right, try again")
 }
} 

Now im not sure how to transfer the variable "email" to the signin method, can anybody tell me how to do that? Thanks

EDIT: Tried useing

    public static void signin(String email) {
} 

and got the error:

Error: The method signin(java.lang.String) in the type signup is not applicable for the arguments

Nick Val
  • 7
  • 2
  • Do you know what method parameters and arguments are? – Savior Jan 22 '18 at 17:24
  • 1
    Possible duplicate of [Passing Variables between methods?](https://stackoverflow.com/questions/19499785/passing-variables-between-methods) – Savior Jan 22 '18 at 17:25
  • Or https://stackoverflow.com/questions/37854137/how-can-we-pass-variables-from-one-method-to-another-in-the-same-class-without-t – Savior Jan 22 '18 at 17:25
  • Or https://stackoverflow.com/questions/8614365/passing-a-string-from-one-method-to-another-method – Savior Jan 22 '18 at 17:26
  • Or even https://stackoverflow.com/questions/31610174/use-variable-which-is-in-main-method-in-another-method – Savior Jan 22 '18 at 17:26
  • Also, once you fix that, you'll need to deal with https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – Savior Jan 22 '18 at 17:29
  • And don't create multiple `Scanner` objects. Create one and use it everywhere. – Savior Jan 22 '18 at 17:29

1 Answers1

0

You are creating a method parameter but not passing it in. When you call the method signin(String email), you need to give it a string that will then be recognized as the variable email.

Try this when calling the method:

signin(email);

Also nitpicking thing but will greatly improve the readability of your code, subsequent words in method names should be capitalized, like this:

signIn(email);
sjpratt
  • 76
  • 1
  • 7