To Lecture Notes

IT 372 -- May 15, 2024

Review Questions

  1. How do you add a new activity to an Android app? How does Android Studio keep track of all the activities in an app?
    Answer: Right click on app in the project explorer of Android Studio.
    Select New >> Activity >> Empty Views Activity
    On the New Activity Dialog, enter the name of the new activity, for example ConfirmationActivity.
  2. 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); 
    
  3. Implement the FromFile Example by displaying 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:
    R,50,50,350,100,#DC143C 
    O,50,200,250,100,#E9967A 
    R,50,350,150,100,#B8860B 
    O,50,500,50,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.myfile);
    Scanner scanner = new Scanner(iStream); 
    
    Answer: Here are the source code files:
    activity_main.xml  Shape.java  MyView.java  MainActivity.java

Project 4

ZooMap App

Introduction to Kotlin