Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- import java.io.*;
- import java.util.*;
- public class davidHashMapDemo
- {
- Scanner keyboard = new Scanner(System.in);
- //Username as key, password as value
- HashMap<String, String>Records = new HashMap<String, String>();
- //Username as key, user's full name as value
- HashMap<String, String>userNames = new HashMap<String, String>();
- //File name from which all user information will be read
- String fileName = "database.txt";
- Scanner inputFile = new Scanner(fileName);
- //Variables to hold pertinent user information
- String userId, firstName, lastName, password;
- StringTokenizer t;
- String current;
- while(inputFile.hasNext())
- {
- current = inputFile.nextLine();
- t = new StringTokenizer(current, " ");
- //Scan the file for user information. This includes first
- //and last name, userId and password.
- while(t.hasMoreTokens())
- {
- firstName = t.nextToken();
- lastName = t.nextToken();
- userId = t.nextToken();
- password = t.nextToken();
- //Bring first and last name together to create
- //full name
- String fullName = firstName+" "+lastName;
- //Add information to each hashmap
- Records.put(userId, password);
- userNames.put(userId, fullName);
- }
- }
- //Ask the user for their information
- System.out.println("UserID: ");
- String id = keyboard.nextLine();
- System.out.println("Password: ");
- String userPassword = keyboard.nextLine();
- //Check to see if user information matches
- //something in the database file
- boolean check = false;
- }
Add Comment
Please, Sign In to add comment