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. Answer:
                  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. Answer:
      Hex Unicode Code:                                 E    1
      Binary Unicode Code:                             1110 0001
      Two Bytes Template:    U+0080  U+07FF  110xxxxx 10xxxxxx
      Match Unicode bits with Template:         00011   100001
      Add UTF-8 code bits 110 and 10:        11000011 10100001
      Regroup into groups of four:                1100 0011 1010 0001
      Rewrite as hex digits:                       C    3    A    1
      Answer:                                      C2A1
      
    2. Find the UTF-8 encoding of the character ♯ (music sharp sign). This character has hex Unicode 266F. Its UTF-encoding requires three bytes.
      Hex Unicode Code:                       2    6    6    F
      Binary Unicode Code:                   0010 0110 0110 1111
      Three bytes template:  U+0800  U+FFFF  1110xxxx 10xxxxxx 10xxxxxx
      Match Unicode bits with Template:          0010   011001   101111
      Add UTF-8 code bits 110 and 10:        11100010 10011001 10101111      
      Regroup into groups of four:        1110 0010 1001 1001 1010 1111              
      Rewrite as hex digits:               E    2    9    9    A    F
      Answer:                              E299AF          
      
  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

Look at these sections in the Introduction to Kotlin document.

ZooMap App