To Lecture Notes

IT 372 -- Apr 15, 2026

Review Questions

  1. Translate these formulas into Java:
    1. a = √(s + 3 t3n)
      Answer:
      double a = Math.sqrt(s + 3 * Math.pow(t, 3 * n));
      
    2. b =
          2 s t1+n
      1 - 5(u + 2)2n

      Answer:
      double b = (2 * s * Math.pow(t * (1 + n)) / 
                 (1 - 5 * Math(u + 2, 2 * n));
      
  2. The following code copies the items from an arraylist declared by
    ArrayList<Integer> al = new ArrayList<Integer>( );
    
    into a string:
    String output = "";
    for(Integer n : al) {
        output += n + "\n";
    }
    
    Perform this operation using a StringBuilder collection instead. If there are many items in the arraylist, using a StringBuilder collection is much faster. Answer
    // Declare ArrayList object and add items to it.
    StringBuilder sb = new StringBuilder("");
    String output = "";
    for(Integer n : a1) {
        a1.append(n + "\n");
    }
    
  3. Add these strings to an ArrayList collection:
    c  java  kotlin  python  
    
    Then use the ArrayList method replaceAll that accepts a lambda function to convert each of the strings to uppercase. Answer:
    ArrayList<String> list = new ArrayList<String>( );
    list.add("c");
    list.add("java");
    list.add("kotlin");
    list.add("python");
    list.replaceAll( s -> s.toUpperCase( ));
    String output = "";
    for(String s : list) {
        output += s + \n");
    }
    TextView tv = findViewById(R.id.txt_output);
    tv.setText(output);
    
  4. Create an Android app with four radio buttons with text Freshman, Sophomore, Junior, Senior. Place them in a radio button group. Add a button with text Show Year that shows the selected year using the codes 1, 2, 3, and 4. Answer:   activity_main.xml  MainActivity.java
  5. What is an Android drop-down menu called?
    Answer: it is called a Spinner.
  6. Set up a spinner that contains the text Freshman, Sophomors, Junior, Senior. Add a button that displays the selected year using the codes 1, 2, 3, and 4.
    Answer: strings.xml  activity_main.xml  MainActivity.java
  7. How do you restrict the inputs to an EditText widget? For example, how do you set it up so that only numbers can be entered?
    Answer: Set the inputType attribute in the EditText widget like this:
    android:inputType="number"
    or
    android:inputType="numberSigned
    or
    android:inputType="numberDecimal"
    
  8. How do you display special characters in a widget?-
    Answer: You can't use HTML entities, but you can use Unicode characters. See the website unicode.org for code charts. For example, the unicode codes for the greek letters alpha (α), beta (β), gamma (γ) are 0BC1, 0BC2, and 0BC3. Here is an attribute that displays these Greek letters in a TextView widget:
    android:text="Greek letters: \u03B1, \u03B2, \u03B3"

The Activity Lifecycle

Some Examples