Implementing a Counter into Java

Activity Overview: This activity is for more advanced students in the Java Programming language. They will use their own IDE to create a program that will take a starting number and allow them to increment and decrement the number. They will start with ++ and then explore how to make other changes to their number. The big idea is to relate counters, incrementing and decrementing, to how this could be applied to loops.

Author: Selena Pope
Grade Level: 9-12
Materials: Online IDE or Eclipse

OVERVIEW

Activity Overview:

Activity Overview: This activity is for more advanced students in the Java Programming language. They will use their own IDE to create a program that will take a starting number and allow them to increment and decrement the number. They will start with ++ and then explore how to make other changes to their number. The big idea is to relate counters, incrementing and decrementing, to how this could be applied to loops.

Meta description

  • Subject Area: Computer Science, Mathematics
  • Grade Level : 9-12
  • Computer Science Domains:
    • Algorithms and Programming
  • Computer Science Principles:
    • Collaborating Around Computing, Recognizing and Defining Computational Problems
  • Materials:
    • Online IDE or Eclipse
  • Considerations: +

Lesson Plan

Overview

Activity Overview: This activity is for more advanced students in the Java Programming language. They will use their own IDE to create a program that will take a starting number and allow them to increment and decrement the number. They will start with ++ and then explore how to make other changes to their number. The big idea is to relate counters, incrementing and decrementing, to how this could be applied to loops.

ASSESSMENT PRE/POST-TEST

Can students create a counter and implement it into a Java program? How are loops and counters related?

OBJECTIVES

implement a counter into a Java program and trace the changes in the value of a named variable.

CATCH/HOOK

Video: https://www.youtube.com/watch?v=wxds6MAtUQ0

ACTIVITY INSTRUCTIONS

Students will watch the video on loops. Teacher will use a real world example to explore the idea of a loop. For example, teacher may list the actions of a simple morning routine. Wake up, make bed, walk to bathroom, turn on faucet, brush teeth, comb hair. If you were coding a robot to do your morning routine, would you want to write this out in code over and over? What if we needed to keep track of how many times the brush went through the hair?

Vocabulary: increment and decrement

Then a simple program will be made using counters (++). The program will have 2 integers as variables myNumber and answer. See attachment for sample program that could be written in an IDE that does Java. Manipulate the program to decrement, instead of increment.

Supplements

Any items in this section are the property & under the license of their respective owners.

REVIEW

Now that we have set the foundation of the counter, can the students draw correlations between how a counter may be used with a loop? We will work with their inferences to tie loops and counters together in a relationship. What if we need to count up or down by more than one such as skip counting? Show students how to do this within their program.

STANDARDS

TypeListing
CS DomainsAlgorithms and Programming
CS PrinciplesCollaborating Around Computing, Recognizing and Defining Computational Problems
Other Content Standards