SE1021
Homework

Week 1 (Review)

Week 2

  • Exercise: 13.1, 13.2, 13.3, 13.6, 13.10, and 13.17

Week 3

  • Exercise: 14.1, 14.3, 14.6, 14.7, 14.10, 14.11, and 14.13

Week 4

  1. Write a simple calculator program that looks like this:

    The program display the result of adding the two numbers together.
  2. Modify the program so that the user cannot modify the answer text field.
  3. Modify the program to color the background of the result text field red if the result is negative, otherwise the background should be light gray.
  4. Modify the program so that if the + is clicked, it turns into a - button; if clicked again, it turns into a * button; if clicked again, it turns into a / button; and if clicked again, returns to a + button.
  5. Modify the program so that if = button is clicked, the appropriate math operation is used to produce the result shown in the last text field.
  6. Modify the program so that hitting enter while in either of the first two text fields is equivalent to pressing the = button.
  7. Suppose you were required to use at least one anonymous inner class in your implementation. Where would you use it, and why?
  8. Modify your program so that it displays "ERROR" with a red background in the result field if either of the input textfields contain invalid information.
  9. Modify your program to add % as a fifth operator option.

Week 5

The following classes may be useful for the exercises below: JFrame, JPanel, JButton, JLabel, JTextField, JCheckBox, JRadioButton, BottonGroup, JTextArea, JScrollPane, JMenu, JMenuItem, JMenuBar, and Font.

  1. Write a simple program that looks like this:
  2. Write a simple program that looks like this:
  3. Write a simple program that looks like this:
  4. Write a simple program that looks like this:
  5. Write a simple program that looks like this:
  6. Write a simple program that looks like this:
  7. Write a simple program that looks like this:

    Note that the text is in a JTextArea that is contained inside a JScrollPane.
  8. Make the program shown in 2 functional.
  9. Add functionality to the program shown in 5 such that the checkboxes become active when the Custom radio button is selected.
  10. For the program in 6 display a dialog box stating "Thanks for your application. We'll get back to you." or "Thanks for your application. Unfortunately we don't have any jobs available at this time." depending on which community standing radiobutton has been selected.
  11. Make the program shown in 7 functional. The Brightness menu has two options that change the background color of the text area.

Week 6

  1. Explain how exception handling increases the robustness of software
  2. Explain why there are multiple classes that derive from the Exception class
  3. What happens when an exception is thrown during the execution of a program but never caught
  4. Consider the following stack trace:
    java.lang.ArithmeticException: / by zero
        at wk6.Homework.method4(Homework.java:26)
        at wk6.Homework.method3(Homework.java:22)
        at wk6.Homework.method2(Homework.java:18)
        at wk6.Homework.method1(Homework.java:11)
        at wk6.Homework.main(Homework.java:6)
    
    What caused the exeception and where (which method) did the exception occur?
  5. Suppose that method1() (from the previous problem) is implemented as follows:
        private static void method1(String string) {
            try {
                method2(string + " birthday");
            } catch (ArithmeticException e) {
                e.printStackTrace();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
            System.out.println("In method1");
        }
    
    What will be the output of the program?
  6. What will happen if the method is implemented as follows:
        private static void method1(String string) {
            try {
                method2(string + " birthday");
            } catch (Exception e) {
                e.printStackTrace();
            } catch (ArithmeticException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("In method1");
        }
    
  7. Describe when throwing an exception is preferred over including error handling code at the source of the error.

Week 9

The following are related to the application that we have been developing in lecture.

  1. Rename LTunnel to DLTurn (indicating that the tile can be entered when going DOWN or to the LEFT).
  2. Create Tile classes to handle the following:
    1. J - DRTurn similar to DLTurn
    2. r - ULTurn similar to DLTurn
    3. 7 - URTurn similar to DLTurn
  3. Each time a new Tile class is added, the GameBoard class must be modified. What could you do to make it so that the GameBoard does not require modification when adding a new Tile type?
  4. Create Tile classes to handle the following:
    1. = - LRTunnel similar to DLTurn
    2. H - UDTunnel similar to DLTurn
    3. * - BombTile causes player to lose if encountered
  5. Create one class, DirectionTile, that handles all four directions:
    • ^ - Only allow player to go up through this tile
    • v - Only allow player to go down through this tile
    • > - Only allow player to go left through this tile
    • < - Only allow player to go right through this tile
  6. Modify game logic so that it automatically loads level1.txt. Once the player wins that level, it should load level2.txt and continue until all the level*.txt files have been completed.
  7. Create additional tile types and level files

Last modified: Monday, 09-Jan-2017 23:00:33 CST