Multiple choice technology web technology

Given: 12. public class AccountManager { 13. private Map accountTotals = new HashMap(); 14. private int retirementFund; 15. 16. public int getBalance(String accountName) { 17. Integer total = (Integer) accountTotals.get(accountName); 18. if (total == null) 19. total = Integer.valueOf(0); 20. return total.intValue(); 21. } 23. public void setBalance(String accountName, int amount) { 24. accountTotals.put(accountName, Integer.valueOf(amount)); 25. } 26. } This class is to be updated to make use of appropriate generic types, with no changes in behavior (for better or worse). Which of these steps could be performed? (Choose three.)

  1. Replace line 13 with private Map<String, int> accountTotals = new HashMap<String, int>();

  2. Replace line 13 with private Map<String, Integer> accountTotals = new HashMap<String, Integer>();

  3. Replace line 13 with private Map<String<Integer>> accountTotals = new HashMap<String<Integer>>();

  4. Replace lines 17–20 with int total = accountTotals.get(accountName); if (total == null) total = 0; return total;

  5. Replace lines 17–20 with Integer total = accountTotals.get(accountName); if (total == null) total = 0; return total;

  6. Replace line 24 with accountTotals.put(accountName, amount);

Reveal answer Fill a bubble to check yourself
B,E,F Correct answer
Explanation

Changing the map to Map enables generics. In lines 17–20, total must be declared as Integer to check for null safely before returning, which automatically unboxes to int. For line 24, autoboxing allows passing the primitive amount directly into the map.