Monthly Archives: October 2015

CSP PD Session on Oct 17, 2015

 

 

 

 

CSP_Oct_2015

 

Rebecca Dovi
As CEO (chief educational officer) of CodeVA Rebecca is responsible for training teachers and developing computer science curriculum as CodeVA works to bring computer science education to all Virginia students.

Introduction to the Random class

Even though the Random class is not included in the apcs curriculum, I find it a great class to use to introduce my students to using objects and methods. I use the nextInt and nextDouble methods to start the conversation of method signatures, parameters and return types; also the difference between inclusive and exclusive values. This is also the first time students are introduced to the “Off-by-One” error!

I used this activity as a warm up then followed it with a notes/discussion. Students ran their program 5 times and recorded the values that were generated by their program.

Random class Intro

During the follow-up discussion, I asked them why the random numbers were considered “psuedorandom” number, leading to a discussion about algorithms.

Following this discussion, I asked my students to write a program to generate the following random numbers:

  1. a random integer between 0 (inclusive) and 15 (inclusive).
  2. a random integer between 20 (inclusive) and 150 (inclusive).
  3. a random decimal between 0.0 (inclusive) and 1 (exclusive).
  4. a random decimal between 0.0 (inclusive) and 20 (exclusive).

Here is a copy of the activity and discussion/notes from this lesson:

Random Class Introduction

Intro to Random Notes

Additional Reading:

HTG Explains: How Computers Generate Random Numbers

I have spent the last 18 years teaching math and computer science at Powhatan High School in Powhatan Virginia. I currently teach Algebra 2, Exploring Computer Science/Game Design, and AP Computer Science. I also facilitate a Middle School Tech Club, Game Design and Tech Divas Summer Camps.

Introduction to the Scanner class

What is the difference between using input.next() and input.nextLine()?

Here is a quick activity to introduce your students to the Scanner class to read input from the console and to discuss the /r/n caused by hitting the enter key.

Before this activity,  I had my students to view the Using the Scanner class online tutorial, provided by James Madison University (CS139), for homework.  I used this activity as a warm up activity.

Intro to Scanner

When my students added the code segments on the back they started to question the code. With Part 1 (favorite food) they noticed that only one word was being brought in by the scanner. Then when they added Part 2 (favorite movie) they thought they broke their program.

As a class, we discussed the information on the front page and with a focus on the meaning of a “token”. At this time, my students understood why they only got one word from their favorite food input. But there was still a mystery about why they were never given the chance to enter their favorite movie.

I keep a vintage typewriter in my classroom as a decoration, but it I use it for this lesson specifically!  It is hard for students to understand that when they hit the “enter key” there are actually adding a carriage return and a line feed (\r\n) to the end of the input stream. These two commands are “grabbed” by the input.nextLine() in part 2 before they can even enter their favorite movie. By demonstrating what happens on the vintage typewriter when you hit enter my students were able to visualize the two events.

To fix this input problem, I had my students add the input.nextLine() statement to “clear the input stream”.

clear input stream

Here is the activity and a copy of the notes from our discussion:

Introduction to the Scanner Class Activity

Intro to Scanner class – Notes

 

 

I have spent the last 18 years teaching math and computer science at Powhatan High School in Powhatan Virginia. I currently teach Algebra 2, Exploring Computer Science/Game Design, and AP Computer Science. I also facilitate a Middle School Tech Club, Game Design and Tech Divas Summer Camps.