Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions