Question: //password.java import java.io.File; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.BufferedReader; import java.nio.file.Files; import java.util.Scanner; import java.io.IOException; import java.util.StringTokenizer; // Data class to represent a password record

//password.java

import java.io.File;

import java.io.FileReader;

import java.io.FileNotFoundException;

import java.io.BufferedReader;

import java.nio.file.Files;

import java.util.Scanner;

import java.io.IOException;

import java.util.StringTokenizer;

// Data class to represent a password record

class Password

{

String userName, password;

public Password(String u, String p) { userName = u; password = p; }

public Password(String r)

{

StringTokenizer st = new StringTokenizer(r.trim(), ",");

userName = st.nextToken(",").trim();

password = st.nextToken(",").trim();

}

public String getUserName() { return userName; }

public String getPassword() { return password; }

public String toString() { return userName + " " + password; }

} // Password

// password.txt

// steven@adamaitis.com, Adamaitis

// janine@addington.com, Addington

//Main.java

public class Password {

public static void main(String[] args) throws FileNotFoundException, IOException) {

String username="", pwd="";

Password[] passwords = new Password[5000];// create an array to store 5000 passwords

//Prompt user to enter username and password

System.out.println("Enter Your user name: ");

Scanner input = new Scanner(System.in);

username=input.nextLine();

System.out.println("Enter Your password: ");

pwd = input.nextLine();

int ctr=0; // counter for the number of passwords

// -------------------------------------------------------

// read the file and store it as a token object

// read the file and store it as a token object

BufferedReader br = null;

String line;

br = new BufferedReader(new FileReader("Password.csv"));

while ((line = br.readLine()) != null) {

System.out.println(line);

StringTokenizer stringTokenizer = new StringTokenizer(line,",");

while (stringTokenizer.hasMoreTokens()) {

passwords[ctr] = new Password(line);

ctr++;

{

for (int k = 0; k

if(username.equalsIgnoreCase(passwords[k].getUserName())&& pwd.equals(passwords[k].getPassword()))

System.out.println("You Are Identified: "+ passwords[k].getUserName()); }

{

br = new BufferedReader(new FileReader("Password.csv"));

while ((line = br.readLine()) != null) {

System.out.println(line);

StringTokenizer stringTokenizer = new StringTokenizer(line);

while (stringTokenizer.hasMoreTokens()) {

//---------------------------------------------------------------------------

//-----------------------------------------------------------------------------

passwords[ctr] = new Password(line);

ctr++;

{

for (int k = 0; k

if(username.equalsIgnoreCase(passwords[k].getUserName())&& pwd.equals(passwords[k].getPassword()))

System.out.println("You Are Identified: "+ passwords[k].getUserName()); }

{

}

}

}

}

}

}

//output

// Could one of the expert please help me fix this program. I am getting an Ecept[on in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5000. This is a runtime error.

I am using Notepad.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!