| 1 | package fun; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | |
| 5 | public class Merced { |
| 6 | |
| 7 | public static void main(String[] args) { |
| 8 | |
| 9 | //Create a new Map, mapping Integers to Strings |
| 10 | HashMap<String, Integer> map=new HashMap<String, Integer>(); |
| 11 | //Associate value 21 with key "Age" |
| 12 | // map.put("Age", 21); |
| 13 | // map.put("Weight", 130); |
| 14 | // //This won't compile since 17.0 is a Double, not an int |
| 15 | // map.put("Age", 17.0); |
| 16 | // map.put("Age", 23); |
| 17 | // //This won't compile since "Tall" is a String, not int |
| 18 | // map.put("Height", "Tall"); |
| 19 | // //What will this return? |
| 20 | // Integer age=map.get("Age"); |
| 21 | // //This will succeed, but return null ("None" in Python) |
| 22 | // Integer ssn=map.get("SSN#"); |
| 23 | // //Won't compile because the return is an Integer |
| 24 | // String weight=map.get("Weight"); |
| 25 | } |
| 26 | |
| 27 | class Person { |
| 28 | |
| 29 | Person(String name_){ |
| 30 | name=name_; |
| 31 | } |
| 32 | |
| 33 | float attractiveness() { |
| 34 | return looks*salary/age; |
| 35 | } |
| 36 | |
| 37 | String name; |
| 38 | int age; |
| 39 | int salary; |
| 40 | float looks; |
| 41 | float brains;//TODO: Irrelevant, remove |
| 42 | |
| 43 | } |
| 44 | |
| 45 | HashMap<String, Person> nameTable=new HashMap<String, Person>(); |
| 46 | |
| 47 | } |