IT 212 Final Exam Review Question Answers Part A: Multiple Choice 1. a 2. c 3. a 4. c 5. b 6. a 7. d 8. d 9. d 10. c 11. b 12. c 13. b 14. c Part B: Predict output of Python code. Problem 1: Variable trace: i b[i] c[i] a[b[i]][c[i]] ----+-----+----+--------------- 0 1 5 a[1][5] == "w" 1 2 1 a[2][1] == "i" 2 0 2 a[0][2] == "n" 3 1 3 a[1][3] == "t" 4 0 4 a[0][4] == "e" 5 1 3 a[1][3] == "r" Output: winter Problem 2: Output: Staff Meeting Room 105 15 14:30 Poker Night Room 109 6/15/2018 20:30 Room 203 True False True False Part C: Convert traditional test to unit test. from monthlyappointment import MonthlyAppointment from onetimeappointment import OneTimeAppointment import unittest class MyUnitTestClass(unittest.TestCase): def test_1(self): appt1 = MonthlyAppointment("Staff Meeting", "Room 105", 15, 20, 30) appt2 = OneTimeAppointment("Poker Night", "Room 109", \ 2018, 6, 15, 20, 30) self.assertEqual(str(appt1), "Staff Meeting Room 105 15 14:30") self.assertEqual(str(appt2), "Poker Night Room 109 6/15/2018 20:30") appt1.location = "Room 203" self.assertEqual(appt.location, "Room 203") self.assertEqual(appt1.occurs_on(2018, 5, 15), True) self.assertEqual(appt1.occurs_on(2018, 5, 17), False) self.assertEqual(appt2.occurs_on(2018, 5, 15), True) self.assertEqual(appt2.occurs_on(2018, 5, 17), False) ) if __name__ == '__main__': unittest.main( ) Part D: Find errors in Java programs. // Problem 1. import java.util.Scanner; public class Overtime { public static void main(String[ ] args) { Scanner s = new Scanner(System.in); System.out.print("Enter the hours worked: "); double hours = Double.parseDouble(s.nextLine( )); System.out.print("Enter the hourly rate: "); double rate = Double.parseDouble(s.nextLine( )); double totalWages; if (hours > 40) { totalWages = (40.0 + (hours - 40.0) * 1.5) * rate; } else { totalWages = hours * rate; } System.out.println("Total Wages: " + totalWages); } } // Problem 2. import java.util.*; public class Magic8Ball { public static void main(String[ ] args) { // Instantiate random number generator Random ranGen = new Random( ); // Choose random number in range [0, 6). int ansNum = ranGen.nextInt(6); // Choose response. String ans; if(ansNum == 0) { ans = "Yes -- definitely"; } else if(ansNum == 1) { ans = "Most likely"; } else if(ansNum == 2) { ans = "Reply hazy, try again"; } else if(ansNum == 3) { ans = "Cannot predict now"; } else if(ansNum == 4) { ans = "Don't count on it"; } else { ans = "Very doubtful"; } // Print answer. System.out.println("Magic eight ball answer: " + ans + "."); } }