Question: I have this Java application for store Password and Id. I have use Map data structure. I want to search stored information by Name, Id

I have this Java application for store Password and Id. I have use Map data structure. I want to search stored information by Name, Id and Date. I need help to add a search data structure algorithm for that. Anyone could help me for that please. My code followed

importjava.io.BufferedWriter; importjava.io.File; importjava.io.FileWriter; importjava.io.IOException; importjava.io.PrintWriter; importjava.time.LocalDateTime; importjava.util.HashMap; importjava.util.Map; importjava.util.Scanner;

public class Users {

public static void main(String[] args) { Map db = new HashMap(); String user,pass; Scanner sc = new Scanner(System.in); while(true) { System.out.println("Please enter username and passeord"); user = sc.next(); pass = sc.next(); db.put(user, pass); try(FileWriter fw = new FileWriter("D:\\WS17.2\\FinalProject\\src\\log.txt", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)){ out.println("The "+ user + " stored in system at "+ LocalDateTime.now()); } catch (IOException e) { System.out.println("Not able to store user "+ user); } System.out.println("Want to terminate then press E or e for Exit"); char choice; choice = sc.next().charAt(0); if(choice == 'E' || choice == 'e') break; } for(Map.Entry m:db.entrySet()){ System.out.println(m.getKey()+" "+m.getValue()); } } }

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!