import java.util.*;

public class KeywordSearch {

Scanner input = new Scanner(new File("keyvalues.txt"));
Map<String, Integer> wordCountMap = getCountMap(in);

    for (String word: wordCountMap.keySet()) {
        int count = wordCountMap.get(word);

 while (input.hasNextLine()) {
        line = input.nextLine();
        numLine++;
        Scanner word = new Scanner(line);
        while (word.hasNext()){
            String nextWord = word.next();
            numWord++;
            numChar = numChar + nextWord.length();
        }

if (salaryMap.containsKey(name)) {
    double salary = salaryMap.get(name);
    System.out.println(name + "'salary is $" salary);
} else {
    System.out.prinln("I don't hava a record for " + name);
}

a program that reads in a file that contains a list of keys and values. Each line of
the file contains a key and a value, separated by whitespace. Using a Scanner, read the
entire file of keys and values into a map. Then, in a loop, prompt the user with "Key:"
read from the console a key. If the key is present in the file, respond with "Key <key>
has value <value>". If the key does not exist, respond with "Key <key> does not exist.
The user types "Q" to exit the program.

Recommended Answers

All 2 Replies

can u write the complete code so that it will be easy to find out what exactly you are trying to do

can u write the complete code so that it will be easy to find out what exactly you are trying to do

import java.io.*;
import java.util.*;

public class Homework10 {

Scanner input = new Scanner(new File("backwards.txt"));

private String reverse_word(String word) {
String new_word = "";
for(int i=word.length()-1; i>=0; i--) {
new_word += word.charAt(i);
}
return new_word;
}

private String reverse_sentence(String sentence) {
String new_sentence = "";
String[] toks = sentence.split(" "); 
for(int i=toks.length-1; i>=0; i--) {
new_sentence += " " + reverse_word(toks[i]);
}
return new_sentence;
}
}

I want to type a number in then i want it to do a keyword search in the text file they return what ever keyword it finds in text file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.