Guest User

Untitled

a guest
Apr 20th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class davidHashMapDemo
  7. {
  8.    
  9.     Scanner keyboard = new Scanner(System.in);
  10.    
  11.     //Username as key, password as value
  12.     HashMap<String, String>Records = new HashMap<String, String>();
  13.     //Username as key, user's full name as value
  14.     HashMap<String, String>userNames = new HashMap<String, String>();
  15.    
  16.     //File name from which all user information will be read
  17.     String fileName = "database.txt";
  18.     Scanner inputFile = new Scanner(fileName);
  19.    
  20.     //Variables to hold pertinent user information
  21.     String userId, firstName, lastName, password;
  22.    
  23.     StringTokenizer t;
  24.     String current;
  25.     while(inputFile.hasNext())
  26.     {
  27.         current = inputFile.nextLine();
  28.         t = new StringTokenizer(current, " ");
  29.        
  30.         //Scan the file for user information. This includes first
  31.         //and last name, userId and password.
  32.         while(t.hasMoreTokens())
  33.         {
  34.             firstName = t.nextToken();
  35.             lastName = t.nextToken();
  36.             userId = t.nextToken();
  37.             password = t.nextToken();
  38.            
  39.             //Bring first and last name together to create
  40.             //full name
  41.             String fullName = firstName+" "+lastName;
  42.             //Add information to each hashmap
  43.             Records.put(userId, password);
  44.             userNames.put(userId, fullName);
  45.         }
  46.     }
  47.    
  48.     //Ask the user for their information
  49.     System.out.println("UserID: ");
  50.     String id = keyboard.nextLine();
  51.     System.out.println("Password: ");
  52.     String userPassword = keyboard.nextLine();
  53.    
  54.     //Check to see if user information matches
  55.     //something in the database file
  56.     boolean check = false;
  57.    
  58.    
  59.    
  60. }
Add Comment
Please, Sign In to add comment