I am a Java beginner.
This is the output I got after testing this class:
Enter username: abc
Enter password: 123
Enter your name and we will call you that: abc123
Enter your position (Manager or Engineer): Manager
Enter your position (Manager or Engineer): Engineer
Enter your position (Manager or Engineer): Manager
Enter your position (Manager or Engineer): Engineer
This loop goes on forever. I think what happens here is the while loop checks the instance variable before the changing of the value and keep checking it or it's something else.
import java.util.*;
public class Employee
{
Scanner inputUsername = new Scanner(System.in);
Scanner inputPassword = new Scanner(System.in);
Scanner inputName = new Scanner(System.in);
Scanner inputPosition = new Scanner(System.in);
private String name;
private String position;
protected String username;
protected String password;
public void signup()
{
System.out.print("Enter username: ");
username = inputUsername.nextLine();
System.out.print("Enter password: ");
password = inputPassword.nextLine();
System.out.print("Enter your name and we will call you that: ");
name = inputName.nextLine();
do
{
System.out.print("Enter your position (Manager or Engineer): ");
position = inputPosition.nextLine();
}while(position != "Manager" || position != "Engineer");
}
}