To Lecture Notes

IT 372 -- May 12, 2025

Review Questions

  1. How do you round off a double value to three digits after the decimal point?
    Answer: Here are two ways to do this:
    // Method 1
    double xRounded = Math.round(x * 1000.0) / 1000.0;
    // Method 2
    String xRounded = String.format("%.3f", x); 
    
  2. For this problem, use the scheme for finding the UTF-8 encoding for a character, given its hex Unicode code:
                  Minimum Maximum Byte 1   Byte 2   Byte 3
                 code    code
                 point   point
    One byte:    U+0000  U+007F  0xxxxxxx 
    Two bytes:   U+0080  U+07FF  110xxxxx 10xxxxxx 
    Three bytes: U+0800  U+FFFF  1110xxxx 10xxxxxx 10xxxxxx
    
    1. Find the UTF-8 encoding of the character á (a with acute accent).  This character has hex Unicode code E1. Its UTF-8 encoding requires two bytes.
    2. Find the UTF-8 encoding of the character ♯ (music sharp sign). This character has hex Unicode 266F. Its UTF-encoding requires three bytes.
  3. Write an app that displays The Raven Poem by Edgar Allen Poe in a textview. Read the poem from the folder res/raw/theraven.txt
    Answer: The layout and Java activity files.
  4. Write an app that displays the picture defined by this text file named shapes.txt:
    R,50,50,350,100,#DC143C
    O,200,200,300,250,#E9967A
    R,50,350,550,450,#B8860B
    O,500,50,600,100,#00FA9A
    
    R means rectangle, O means oval. The fields are x and y coordinates of the upper left corner, and the width and height of the rectangle or of the bounding rectangle for the ovals. The last field is the hex color code.

    Save this data in res/raw/drawing.txt and access it in onCreate like this:
    InputStream iStream = getResources( ).
        openRawResource(R.raw.drawing);
    Scanner scanner = new Scanner(iStream); 
    
    Answer: Here are the source code files:
    activity_main.xml  Shape.java  MyView.java  MainActivity.java
  5. Look at the DrawRivers Example.
  6. How could you use radio buttons to control the radius and color of a circle that you draw using touch event info?

Project 4

Introduction to Kotlin

ZooMap App