Example Webinar on Variables and Operators


Ask the students the following questions and wait for them to answer. If they don’t answer right away select a person to answer. If they still don’t know show them http://interactivepython.org/runestone/static/JavaReview/VariableBasics/vIntro.html#variable-types-on-the-exam

What are the primitive variables that you need to know for the exam? int, double, and boolean (String is an object variable not a primitive variable)

How do you declare a variable? type name; to just declare it or type name = value; to declare and initialize the variable’s value.

Ask the students to type the following declarations in the chat window.

Declare a variable and initialize it for your age.

int age = 18;

Declare a variable and initialize it for your shoe size.

double shoeSize = 9.5;

Declare a variable and initialize it to show if it is raining or not.

boolean raining = true;

You can also do some problems on Practice-It! like http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+2&problem=bjp3-2-s7-studentVariables and http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+2&problem=bjp3-2-s6-fitnessVariables You will need to have an account on Practice-It to get access, but an account is free.

Which type takes up the most memory (see http://interactivepython.org/runestone/static/JavaReview/VariableBasics/declareVars.html) double is bigger than int which is bigger than boolean (could be just one bit but the size isn’t specified in the language standard)


Ask the students what happens when you set one variable x to the value of another y as in x = y?

The memory that represents x is set to a copy of the value in the memory for y and y is not changed. There isn’t a relationship between x and y so that if y changes later x isn’t also changed.

Add the following code at the end of active code 2 at http://interactivepython.org/runestone/static/JavaReview/VariableBasics/changeVars.html and ask the students to predict what the values in x and y will be at the end.

y = 5;

You can use the code visualizer to step through this code and see the values of each of the variables here.

Ask the students to figure out the answer for the multiple choice question 3-3-1 on the same page. Copy this code into active code 2 inside the main method and add System.out.println statements to print the values.


and run that code to show what happens. You can also step through the code using the code visualizer here.

Challenge the students to solve the mixed up code problem on that same page. They will probably just try

x = y;
y = x;

have them think about why that won’t work and why you need a temporary variable.

Do some practice problems on Practice-It! like http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+2&problem=bjp3-2-s11-valuesOfABC


Students usually don’t have trouble with most of the operators but the results of integer division may surprise them. Ask them to predict what will be printed when ActiveCode 1 on page http://interactivepython.org/runestone/static/JavaReview/VariableBasics/operators.html runs. Then talk about why 2 / 3 is 0.

Next ask them to predict what will be printed when ActiveCode 2 runs. Point out that a smaller number modulo a bigger number will always be the smaller number since the bigger number will go in 0 times.

Ask them to answer the multiple choice questions 3-4-1 and 3-4-2.

You can do practice problems on Pracetice-It! like http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+2&problem=bjp3-2-s2-expressions1 and http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+2&problem=bjp3-2-s12-firstSecond

Shortcut Operators

On page http://interactivepython.org/runestone/static/JavaReview/VariableBasics/operators.html run ActiveCode 4 and then have them try to answer multiple choice 3-4-3.

Casting Variables

Go to http://interactivepython.org/runestone/static/JavaReview/VariableBasics/casting.html and make them predict what the output will be from ActiveCode 1 and then run it.

Ask them the answer to multiple-choice 3-5-3.

Integer Min and Max

Go to http://interactivepython.org/runestone/static/JavaReview/VariableBasics/minAndMax.html and ask them to predict what the output will be of ActiveCode 1.

Random Numbers

On page http://interactivepython.org/runestone/static/JavaReview/VariableBasics/randomNumbers.html run ActiveCode 1 and ask them for suggestions for how you could modify it to print a random number from 1 to 10. Remind them about casting to int to get rid of the fractional part.

Here is one way to do it.

public class Test3
   public static void main(String[] args)
     System.out.println((int) (Math.random() * 10) + 1);

Ask them to solve 3-7-1 and discuss why the answers are right or wrong.

Next Section - Example Webinar on Strings