cNVZjGXB
2017-01-11 23:40:09

package loginLab;	

import java.util.Scanner;
public class AccountLogin
{
static Account[] AccountData = new Account[33]; // Create array of usernames and passwords

public static void main(String []args)
{
boolean exitMain = false;
int weirdBug = 0; // Counter so the print statement doesn't print twice, strange error
Scanner in = new Scanner(System.in);
while (exitMain == false)
{
int accountNum = 0; // Account number counter
if (weirdBug % 2 == 0)
{
System.out.println("Would you like to *login* to your account, *create* an account, or *exit*?");
}
weirdBug++;
String command = in.nextLine();
command = command.toLowerCase();
if (command.equals("create"))
{
boolean exitCreate = false;
while (exitCreate == false)
{
System.out.println("Enter a username: ");
String inputUser = in.nextLine();
System.out.println("Enter a numeric password: ");
int inputPass = in.nextInt();
if (accountNum < 33)
{
AccountData[accountNum] = new Account(inputUser, inputPass);
accountNum++;
exitCreate = true;
}
else
{
System.out.println("No more accounts can be created.");
exitCreate = true;
}
}
}
else if (command.equals("login"))
{
System.out.println("Enter your username: ");
String username = in.nextLine();
System.out.println("Enter your password: ");
int password = in.nextInt();
int searchCount = 0;
boolean exitLogin = false;
while (exitLogin == false && searchCount <= accountNum)
{
if (username.equals(AccountData[searchCount].username) && (password == AccountData[searchCount].password))
{
System.out.println("Welcome. \nProgram will now exit.");
exitLogin = true;
exitMain = true;
}
searchCount++;
}
}
else if (command.equals("exit"))
{
System.out.println("Entered \"exit\". Program will now exit.");
exitMain = true;
}
}
in.close();
}
}