Teaching / ProcessingExercises


Teaching.ProcessingExercises History

Hide minor edits - Show changes to markup

September 23, 2009, at 11:58 AM by 136.159.7.119 -
Added lines 10-37:

Conditionals

  1. Try to evaluate the following numerical expressions in your head, then use Processing to check your results:
    1. 5 % 2
    2. 9 % 5
    3. 15 % 12
    4. 12 % 15
    5. 6 % 6
    6. 0 % 7
    7. 7 % 0
What happened with the last example? Why? If you were able to correctly anticipate the computer’s response in all but the last one, it is time to move on. If not, take time now to make up examples of your own. Explore the modulus operator until you are confident you understand how it works.
  1. p and q are boolean variables. Evaluate each of the following expressions for all four combinations of values for p and q.
    1. !(p || q)
    2. p && q
    3. !(p && q)
    4. !p or !q
    5. !p and !q
Which of these are logically equivalent?
  1. The following Processing program draws a simple house.\\
  size( 320, 240 );
rect( 20, 120, 100, 100 ); // the house
rect( 55, 170, 30, 50 ); // the door
rect( 40, 140, 20, 20 ); // the left window
rect( 80, 140, 20, 20 ); // the right window
line( 20, 120, 70, 60 ); // the left roof
line( 70, 60, 120, 120 ); // the right roof
Modify this code to place five houses on the display in different locations.
September 23, 2009, at 11:32 AM by 136.159.7.119 -
Added line 5:

Variables, Expressions and Statements

September 23, 2009, at 11:31 AM by 136.159.7.119 -
Changed lines 4-5 from:
  • Dale, Weens and Headington, Programming and Problem solving with Java, Jones and Bartlett, 2003.
to:
Changed lines 9-20 from:
  1. What is the value of the following Processing expression?
    5 % 2
  2. What is the result of evaluating the following expression?
    (1 + 2 * 2) / 2 + 1
  3. How would you write the following formula as a Processing expression that produces a floating-point value as a result?
    {$ 9/5c + 32 $}
  4. Which of the following are syntactically correct Processing statements? (assume all variables are int)
    • x * y = c;
    • y = con;
    • int x;
    • a = b % c;
  5. f '''
to:
September 23, 2009, at 11:24 AM by 136.159.7.119 -
Changed lines 6-20 from:
to:
  1. Take the sentence: All work and no play makes Jack a dull boy. Store each word in a separate variable, then print out the sentence on one line using println.
  2. Add parenthesis to the expression 6 * 1 - 2 to change its value from 4 to -6.
  3. In Processing, write a program that create a variable named bruce. The program should print the value the expression bruce + 4. Alter your program so that the value printed is 10.
  4. What is the value of the following Processing expression?
    5 % 2
  5. What is the result of evaluating the following expression?
    (1 + 2 * 2) / 2 + 1
  6. How would you write the following formula as a Processing expression that produces a floating-point value as a result?
    {$ 9/5c + 32 $}
  7. Which of the following are syntactically correct Processing statements? (assume all variables are int)
    • x * y = c;
    • y = con;
    • int x;
    • a = b % c;
  8. f '''
September 23, 2009, at 11:00 AM by 136.159.7.119 -
Changed lines 2-5 from:

Adapted from J Elkner, AB Downey, and C Meyers, How to Think Like a Computer Scientist.

to:

Adapted from

  • Elkner, Downey, and Meyers, How to Think Like a Computer Scientist.
  • Dale, Weens and Headington, Programming and Problem solving with Java, Jones and Bartlett, 2003.
September 23, 2009, at 10:47 AM by 136.159.7.119 -
Added lines 1-3:

Processing Exercises

Adapted from J Elkner, AB Downey, and C Meyers, How to Think Like a Computer Scientist.

Page last modified on September 23, 2009, at 11:58 AM