Beginners question on Functions....
in
Programming Questions
•
2 years ago
Hi
I am working on an assignment and trying to write a function that will search against a hashmap and return the found string as a a variable (see below). I keep getting 'Return type for the method is missing' - I haven't called the setup or draw functions - just trying to get this to work on its own for the moment and not sure if that is possible.
Any tips would be gratefully received!
Thanks
slyncie
----------------------------------------------------------------
//puts rules into map
HashMap rulesMap = new HashMap();
rulesMap.put("bg", "ac");
rulesMap.put("em", "ns");
rulesMap.put("pq", "rt");
rulesMap.put("ac", "dj");
rulesMap.put("ns", "pq");
rulesMap.put("ki", "uv");
//sets goal variable
String goal = "dj";
//function to search rules for antecedent and returns corresponding lhs
String searchRules(String goal) {
String leftHandSide = (String) rulesMap.get(goal);
if(leftHandSide != null) {
println("Value mapped to lhs is " + leftHandSide);
return leftHandSide;
} else {
println("No Value mapped with key");
}
}
I am working on an assignment and trying to write a function that will search against a hashmap and return the found string as a a variable (see below). I keep getting 'Return type for the method is missing' - I haven't called the setup or draw functions - just trying to get this to work on its own for the moment and not sure if that is possible.
Any tips would be gratefully received!
Thanks
slyncie
----------------------------------------------------------------
//puts rules into map
HashMap rulesMap = new HashMap();
rulesMap.put("bg", "ac");
rulesMap.put("em", "ns");
rulesMap.put("pq", "rt");
rulesMap.put("ac", "dj");
rulesMap.put("ns", "pq");
rulesMap.put("ki", "uv");
//sets goal variable
String goal = "dj";
//function to search rules for antecedent and returns corresponding lhs
String searchRules(String goal) {
String leftHandSide = (String) rulesMap.get(goal);
if(leftHandSide != null) {
println("Value mapped to lhs is " + leftHandSide);
return leftHandSide;
} else {
println("No Value mapped with key");
}
}
1