
package hashmap;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;

/* student version
/* This project does not implement the Map interface
 * This project is simpler than that, and it will implement a subset
 * of the Map interface methods
 * This project will use an ArrayList, rather than a linked list,
 * to implement the bucket for a given hashcode
 * 
 */
public class HashMapMain 
{
    // TO DO: declare some variables
    // declare a Set of Strings called 'set':
    
    // declare a Java library HashMap with keys that are Strings
    // and values that are BankAccounts.  The HashMap is called 'jmap':
 
    // declare the variable 'myMap' which is of type HashMap
    // HashMap.java is the homegrown version, not the Java library:

    private FileReader reader;
    private BufferedReader in;
    // Give a value to NUM_BUCKETS.  See the comment in ID.java
    private final int NUM_BUCKETS = 
    private Scanner input;
    
    public HashMapMain() throws IOException
    {
        reader = new FileReader("BankAccountData.dat");
        in = new BufferedReader(reader);

        // TO DO: create these variables:
        // create 'set' as a (Java library) HashSet of Strings:
       
        // create 'myMap' as a HashMap, initializing it with NUM_BUCKETS:

        // create 'jmap' as a (Java library) HashMap, initializing it with NUM_BUCKETS:
 
        input = new Scanner(System.in);
        
    }
    public void readInAndStoreValues() throws IOException
    {
    String line = "", ID, initials, date, balanceStr;
    double balance;
    for (int k = 0; k < 10000; k++)
    {   
        line = in.readLine();
      
        // TO DO: follow the comments below
        // create a StringTokenizer, sending to it 'line':
        StringTokenizer token = new StringTokenizer(line);
        // call 'nextToken' to read an account's ID:
    
        set.add(ID);
        // read in the account's initials:
   
        // read the account's balance into 'balanceStr':
      
        // call 'Double.parseDouble' to convert 'balanceStr' to 'balance':
  
        // read the account's date into 'date':
      
        // create the BankAccount 'account':
  
        // store the new BankAccount object in each of the 2 HashMaps:
    
    } //end for loop
    } // end method
    
    /* This menu runs a menu that allows the user to make an interactive choice */
    public void runMenu()
    {   String msg2 = "Welcome to the MHS HashMap-based Bank Account program";
        System.out.println(msg2);
        String msg = "\nTo do: \n1. Add account\n";
        msg += "2. Delete account\n";
        msg += "3. Look for account\n";
        msg += "4. Print account info\n";
        msg += "5. Quit\n";
        msg += "Selection: ";
        String msgOut = "", ID2 = "", initials2 = "", date2 = "";
        double balance2 = 0;
        String balanceStr = "";
        BankAccount ac, ac2;
        int option2 = 0;
        boolean ok = true;
        do
        {
        System.out.print(msg); 
        String option = input.next();
        option2 = Integer.parseInt(option);
        if(option2 == 1)
        {   msgOut = "\nAdding new account:\n";
            msgOut += "Account ID: ";
            System.out.print(msgOut);
            ID2 = input.next();
            // TO DO: using 'myMap', check if this ID already exists
            // if it does print out a message saying that & do nothing more
         
            // TO DO: write the 'else' for the above IF 
            // Ask for the initials of the account holder and get
            // the user's response with 'input.next()':
     
            // do the same for the account's balance:
        
            // do the same for the account's date:
       
            // create a BankAccount object with these data:

            // put the new account into 'myMap':

            // print a message that the account has been added.  
            // Also print how many steps it took:
         
            // using the Java library 'jmap':
            // just as with 'myMap', if the ID is already in use in 'jmap',
            // print a message saying that:
         
            // write the else for that IF.  Use the variables read in above.
            // Create a new account and add it to 'jmap'
            // Print a message that the account was successfully added:
       
        } // end option2 == 1
        else if (option2 == 2)
        {
            msgOut = "\nDeleting an account:\n";
            msgOut += "Enter account number: ";
            System.out.print(msgOut);
            ID2 = input.next();
            // TO DO: follow the comments below
            // using 'myMap', remove this account & store the returned boolean:
     
            // if the account was successfully removed, say so & print out how many steps it took:
      
            // if the account was not found, say so & print out how many steps it took:
       
            // using 'jmap', do the same thing.  The 'remove' method of the
            // Java library HashMap returns the removed BankAccount (not a boolean):
        
        } // end option2 == 2
        else if (option2 == 3)
        {   msgOut = "\nSearching for an account:\n";
            msgOut += "Enter account number: ";
            System.out.print(msgOut);
            ID2 = input.next();
            // using 'myMap', check if the given ID is present.  If it is,
            // print a message that it was found & print how many steps it took.
            // If it was not found, say that & print the number of steps:
     
            // using 'jmap', do the same thing:
        
        } // end if option2 == 3
        else if (option2 == 4)
        {   msgOut = "\nPrinting account info:\n";
            msgOut += "Enter account number: ";
            System.out.print(msgOut);
            ID2 = input.next();
            // using 'myMap' get the account associated with this ID
            // if this is not successful, print an error message
            // & the number of steps it took.
            // if it is successful, call the 'toString' method of the
            // BankAccount class to print information on the account
            // & also print the number of steps required:
        
            // using 'jmap' do the same thing:
    
        } // end if option2 == 4
        else
        {
            msgOut = "\nGoodbye.\n";
            System.out.println(msgOut);
        } // end if option2 == 5
        } while (option2 != 5);
    } // end method
    
    public static void main(String[] args) throws IOException
    {
        HashMapMain hmm = new HashMapMain();
        hmm.readInAndStoreValues();
        hmm.runMenu();
    }
    
} // end class
