Homework: The Java Collections Framework II


This homework is necessary preparation for the lab. Make sure you type your code and you bring the file to the lab so that you will not have to waste time entering it during the lab.

  1. Write the body of the following static method, which, given a components.map.Map<String, Integer> representing employee names and corresponding salaries, raises (by the given percentage) the salary of every employee whose name starts with the given initial. Note that only simple integer arithmetic is needed to satisfy the postcondition.
        /**
         * Raises the salary of all the employees in {@code map} whose name starts
         * with the given {@code initial} by the given {@code raisePercent}.
         * 
         * @param map
         *            the name to salary map
         * @param initial
         *            the initial of names of employees to be given a raise
         * @param raisePercent
         *            the raise to be given as a percentage of the current salary
         * @updates map
         * @requires [the salaries in map are positive]  and  raisePercent > 0
         * @ensures <pre>
         * DOMAIN(map) = DOMAIN(#map)  and
         * [the salaries of the employees in map whose names start with the given
         *  initial have been increased by raisePercent percent (and truncated to
         *  the nearest integer); all other employees have the same salary]
         * </pre>
         */
        private static void giveRaise(components.map.Map<String, Integer> map,
                char initial, int raisePercent) {...}
    
  2. Write the body of the following static method. It has the exact same contract as the previous one, but uses only standard Java components, including java.util.Map<String, Integer>.
        /**
         * Raises the salary of all the employees in {@code map} whose name starts
         * with the given {@code initial} by the given {@code raisePercent}.
         * 
         * @param map
         *            the name to salary map
         * @param initial
         *            the initial of names of employees to be given a raise
         * @param raisePercent
         *            the raise to be given as a percentage of the current salary
         * @updates map
         * @requires <pre>
         * [the salaries in map are positive]  and  raisePercent > 0  and
         * [the dynamic types of map and of all objects reachable from map
         *  (including any objects returned by operations (such as entrySet() and,
         *  from there, iterator()), and so on, recursively) support all
         *  optional operations]
         * </pre>
         * @ensures <pre>
         * DOMAIN(map) = DOMAIN(#map)  and
         * [the salaries of the employees in map whose names start with the given
         *  initial have been increased by raisePercent percent (and truncated to
         *  the nearest integer); all other employees have the same salary]
         * </pre>
         */
        private static void giveRaise(java.util.Map<String, Integer> map,
                char initial, int raisePercent) {...}