CS 2113 Software Engineering - Spring 2022 | CS 2113 Software Engineering.

This worksheet is out of date and will need to be updated

Worksheet: J6

Worksheets are self-guided activities that reinforce lectures. They are not graded for accuracy, only for completion. Worksheets are due by Sunday night before the next lecture.

Questions

  1. Why is Exception and Error handling important in relation to GUIs and writing an application that has an abstraction of user input to other threads?

  2. To help you in the next few questions, briefly describe how a mouseReleased event differs from a mousePressed event. Are both of these events happening equivalent to 2 mouse clicks?

    Hint: The documentation can help

  3. Write a program that creates a window, and draws a rectangle that is your favorite color. Extend this program so that the rectangle will rotate 90 degrees clockwise when it is left-clicked.

    Hint 1: A Graphics2d object has built in functions for rotation. This might help you find the function.

    Hint 2: The rotate function requires the rotation metric to be specified in a particular measurement (found in the documentation). Math.toRadians() might be of help

  4. Extend your program from the previous question by adding the following functionalities:

    * When your mouse goes  within the bounds of the object, it should change to a different color than it originally is.
    * When your mouse exits the bounds of the object it should revert to the original color
    

  5. Animate your rectangle’s rotation so that the rotation is visible. This can be done with multiple calls to rotation with a small rotation angle.

  6. Did you experience any challenges with your object actually updating to the changes? If so, what were they and how did you solve them? If not, what mechanism in your code was responsible for ensuring it updated?

  7. As a reminder, the InputStream class is useful for byte-by-byte reading, or reading a group of bytes. The Reader class works on characters and groups of characters, and the Scanner class allows for token-based reading.

    For each class, briefly describe a program in which you would use that class, and what functionality would be enabled by choosing that class specifically. Be as specific as possible.

  8. Imagine that you wanted to reverse-engineer some piece of malware that you know was compiled with c. You know the file you are being asked to reverse-engineer contains a sequence of bytes that is present in all versions of such malware. The signature can be initialized with

    byte[] signature = "while(file_exists){delete_file();}".getBytes()
    

    Sketch out the beginning of a Java program that would take an executable file evil_malware, and be able to read it in to check for the signature.

    Note: Here we are assuming that we used the -XX:+UseCompressedStrings flag for our JMV so that our chars can be in the same format as c strings.

  9. If you were writing a web scraper that needed to download a rather large file, which of the input methods that we have discussed would you extend to fulfill your needs? Assume you are working on a machine in which the network speed allowed you to download at a faster rate than you can write to disk, and your working memory avialable to your program is not enough to store the whole file in memory before writing. Describe your implementation at a high level, ensuring that you describe specific functionality your program would have to solve this problem.