Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble with my login function. It's not reading the array except for the first item in the list and I am having

I am having trouble with my login function. It's not reading the array except for the first item in the list and I am having trouble exiting the double loop and when I tried using a 'outerloop:' statement but only got error messages. So I am at a complete loss as to what to do now. Please help!

private static File initial_Login(Scanner scanner, String name) { File fname = null; String[] user = {"GreenTinker", "Max6Hero", "AquaTattoos", "LlamaEmperor", "VikingTooth"}; String[] pw = {"FairyGreen", "HeroBALALALA", "Swim3Red", "KuzcoDynasty", "BlackDragon"}; for (int z = 0; z < user.length; z++) { //Checks if username and password is in the lists. System.out.println("Please enter in your username: "); String username = scanner.nextLine(); for (int y = 0; y < pw.length; y++) { System.out.println("Please enter in your password: "); String word = scanner.nextLine(); if ((user[z].equals(username)) || (pw[y].equals(word))) { //Checks if username and password match. if ((user[0].equals(username)) == (pw[0].equals(word))) { name = "Tinker Bell"; fname = new File("Tinker Bell.txt"); break; } else if ((user[1].equals(username)) == (pw[1].equals(word))) { name = "Hiro Hamada"; fname = new File("Hiro Hamada.txt"); break; } else if ((user[2].equals(username)) == (pw[2].equals(word))) { name = "Arthur Curry"; fname = new File("Arthur Curry.txt"); break; } else if ((user[3].equals(username)) == (pw[3].equals(word))) { name = "Emperor Kuzco"; fname = new File("Emperor Kuzco.txt"); break; } else if ((user[4].equals(username)) == (pw[4].equals(word))) { name = "Hiccup Horrendous Haddock III"; fname = new File("Hiccup Horrendous Haddock III.txt"); break; } else { System.out.println("Username and Password do not match."); continue; } } else { System.out.println("Incorrect Username and Password"); continue; } } System.out.printf("Welcome " + name); } return fname; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions