当前位置: 代码迷 >> Java相关 >> 刚学Java,请帮忙看看这两个类,为什么会显示找不到符号
  详细解决方案

刚学Java,请帮忙看看这两个类,为什么会显示找不到符号

热度:254   发布时间:2008-05-14 23:13:49.0
刚学Java,请帮忙看看这两个类,为什么会显示找不到符号
包都是用的import java.*
public class InputReader
{
    public HashSet<String>getInput()
    {
        System.out.print("> ");
        String inputLine=reader.nextLine().trim().toLowerCase();
        String[] wordArray=inputLine.split(" ");
        HashSet<String>words=new HashSet<String>();
        for(String word:wordArray){
            words.add(word);
        }
        return words;
    }
}
public class Responder
{
   
   public Responder()
   {
       responseMap=new HashMap<String,String>();
       fillResponseMap();
    }
   private void fillResponseMap()
   {
       responseMap.put("slow","I think this has to do with your hardware.\n");
       responseMap.put("bug","Well,you know,all software has some bugs.\n");
       responseMap.put("expensive","The cost of our product is quite competitive.\n");
    }
   public String generateResponse(HashSet<String> words)
   {   
       Iterator<String> it=words.iterator();
       while (it.hasNext())
       {
       String word=it.next();
       String response=responseMap.get(word);
           if(response!=null){
               return response;
            }
        }
        return pickDefaultResponse();
    }
   public String pickDefaultResponse()
   {
       return("I need more information.");
    }
}
搜索更多相关的解决方案: Java  String  符号  public  Responder  

----------------解决方案--------------------------------------------------------
可以编译通过了
import java.*;
import java.util.*;
class InputReader
{
    public HashSet<String>getInput()
    {
        System.out.print("> ");
        Scanner sc = new Scanner(System.in);
        String inputLine=sc.nextLine().trim().toLowerCase();
        String[] wordArray=inputLine.split(" ");
        HashSet<String>words=new HashSet<String>();
        for(String word:wordArray){
            words.add(word);
        }
        return words;
    }
}
class Responder
{  
   HashMap<String,String> responseMap;
   
   public Responder()
   {
       responseMap=new HashMap<String,String>();
       fillResponseMap();
    }
   private void fillResponseMap()
   {
       responseMap.put("slow","I think this has to do with your hardware.\n");
       responseMap.put("bug","Well,you know,all software has some bugs.\n");
       responseMap.put("expensive","The cost of our product is quite competitive.\n");
    }
   public String generateResponse(HashSet<String> words)
   {   
       Iterator<String> it=words.iterator();
       while (it.hasNext())
       {
       String word=it.next();
       String response=responseMap.get(word);
           if(response!=null){
               return response;
            }
        }
        return pickDefaultResponse();
    }
   public String pickDefaultResponse()
   {
       return("I need more information.");
    }
}
----------------解决方案--------------------------------------------------------
谢谢
----------------解决方案--------------------------------------------------------
  相关解决方案