@@ -0,0 +1,2697 @@
+public class BatteryCharger%0A%7B%0A    /**%0A     * rateTable has 24 entries representing the charging costs for hours 0 through 23.%0A     */%0A    private int%5B%5D rateTable;%0A%0A    public BatteryCharger()%0A    %7B%0A        int%5B%5D table = %7B50, 60, 160, 60, 80, 100, 100, 120, 150, 150, 150, 200,%0A                40, 240, 220, 220, 200, 200, 180, 180, 140, 100, 80, 60%7D;%0A        rateTable = table;%0A    %7D%0A%0A    /** Determines the total cost to charge the battery starting at the beginning of startHour.%0A     * @param startHour the hour at which the charge period begins%0A     *   Precondition: 0 %E2%89%A4 startHour %E2%89%A4 23%0A     * @param chargeTime the number of hours the battery needs to be charged%0A     *   Precondition: chargeTime %3E 0%0A     * @return the total cost to charge the battery%0A     */%0A    private int getChargingCost(int startHour, int chargeTime) %7B%0A        int total = 0;%0A        for (int i=startHour; i%3CstartHour+chargeTime; i++) %7B%0A            total += rateTable%5Bi %25 24%5D;%0A        %7D%0A        return total;%0A    %7D%0A%0A    /** Determines start time to charge the battery at the lowest cost for the given charge time.%0A     * @param chargeTime the number of hours the battery needs to be charged%0A     *   Precondition: chargeTime %3E 0%0A     * @return an optimal start time, with 0 %E2%89%A4 returned value %E2%89%A4 23%0A     */%0A    public int getChargeStartTime(int chargeTime) %7B%0A        int cost = Integer.MAX_VALUE;%0A        int hour = 0;%0A        for (int i=0; i%3C24; i++) %7B%0A            int newCost = getChargingCost(i, chargeTime);%0A            if (newCost %3C cost) %7B%0A                cost = newCost;%0A                hour = i;%0A            %7D%0A        %7D%0A        return hour;%0A    %7D%0A%0A    /*************************************************%0A     * The main method is complete.%0A     *%0A     * See correct output below...%0A     *%0A     * Cost:%0A     * 40%0A     * 110%0A     * 550%0A     * 3710%0A     *%0A     * Best starting time:%0A     * 12%0A     * 0%0A     * 22%0A     * 22%0A     **************************************************/%0A    public static void main(String%5B%5D args)%0A    %7B%0A        BatteryCharger charger = new BatteryCharger();%0A%0A        System.out.println(%22Cost:%22);%0A        System.out.println(charger.getChargingCost(12, 1));%0A        System.out.println(charger.getChargingCost(0, 2));%0A        System.out.println(charger.getChargingCost(22, 7));%0A        System.out.println(charger.getChargingCost(22, 30));%0A        System.out.println();%0A%0A        System.out.println(%22Best starting time:%22);%0A        System.out.println(charger.getChargeStartTime(1));%0A        System.out.println(charger.getChargeStartTime(2));%0A        System.out.println(charger.getChargeStartTime(7));%0A        System.out.println(charger.getChargeStartTime(30));%0A        System.out.println();%0A    %7D%0A%0A%7D%0A

Add BatteryCharger