刚学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.");
}
}
----------------解决方案--------------------------------------------------------
可以编译通过了
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.");
}
}
----------------解决方案--------------------------------------------------------
谢谢
----------------解决方案--------------------------------------------------------