CSE 201 - Homework 2


Read Chapter 2 in the textbook (specifically: Sections 2.1-2.5, 2.9-2.13, 2.15; in other words, for now you can skip Sections 2.6, 2.7, 2.8, 2.14) and then answer the following questions.

  1. Briefly describe the concept of a program variable. What is it? What is it used for?
  2. 
           
  3. Briefly describe the concept of a program type. What is it? What is it used for?
  4. 
           
  5. What is the purpose of an assignment statement? What does it do?
  6. 
           
  7. Given the following declarations, evaluate each of the expressions below.
        int age = 21;
        double pi = 3.1415;
        double radius = 2.7;
        String phrase = "To be or not to be";
        char letter = 'X';
    
    1. 2.0 * pi * radius
    2. "phrase is " + phrase.length() + " characters long"
    3. phrase.indexOf("not")
    4. phrase.substring(3, 12)
    5. phrase + ", that is the question."
    6. age / 4
    7. age % 4
    8. (age % 30) - (age / 30)
  8. 
           
  9. Write a complete Java program that asks the user for a date, and reads the date entered by the user, and finally prints a friendly message. Here is a sample run of the program (user input is in bold). You don't need to worry about checking that the input is in the correct format.
  10.     Please enter today's date: Sunday, October 3
        Today is Sunday, October 3. What a great day!