Hi, I am trying to compile this program. It works perfectly for 2 Strings(Name, phone number) But not for 3 Strings (Name, phone number and sex).
CODE (Not working code - 3 Strings (Name, phone number and sex))
import java.util.Map;
import java.util.TreeMap;
public class Ann {
String name, phone;
public Ann() {
}
public static void testMap() {
Map<String, String, String> theMap = new TreeMap<String, String,String>();
// new HashMap<K,V>(); could also be used
theMap.put("Roger M", "090-997-2918", "Male");
theMap.put("Jane M", "090-997-1987", "FeMale");
theMap.put("Stacy K", "090-997-9188", "FeMale");
theMap.put("Gary G", "201-119-8765", "Male");
theMap.put("Jane M", "090-233-0000", "FeMale");
System.out.println("Testing TreeMap and Map");
System.out.print("Stacy K has phone ");
System.out.print(theMap.get("Stacy K"));
System.out.print("\n");
System.out.print("Jane M has phone ");
System.out.print(theMap.get("Jane M"));
} // testMap()
public static void main(String[] args) {
testMap();
}
}
ERROR
wrong number of type arguments; required 2
wrong number of type arguments; required 2
WORKING CODE (For 2 Strings (Name, phonenumber))
import java.util.Map;
import java.util.TreeMap;
public class Ann {
String name, phone;
public Ann() {
}
public static void testMap() {
Map<String, String> theMap = new TreeMap<String, String>();
// new HashMap<K,V>(); could also be used
theMap.put("Roger M", "090-997-2918");
theMap.put("Jane M", "090-997-1987");
theMap.put("Stacy K", "090-997-9188");
theMap.put("Gary G", "201-119-8765");
theMap.put("Jane M", "090-233-0000");
System.out.println("Testing TreeMap and Map");
System.out.print("Stacy K has phone ");
System.out.print(theMap.get("Stacy K"));
System.out.print("\n");
System.out.print("Jane M has phone ");
System.out.print(theMap.get("Jane M"));
} // testMap()
public static void main(String[] args) {
testMap();
}
}
I want the code to work for about 5 attributes like name , phone, sex,age,address. If someone can help me compile the code at the top of the question, I can figure out the rest.
Thanks