Objectives

Students will be able to:

  • understand the difference between local and global variables and when/how to use them.

Variable Scope

 

Scenario

A computer program simulating a disaster warning system generates and evaluates a random number representing a rainfall level in Tokyo, Japan.

Here is the for the simulator.

Task

Open the worksheet and complete Tasks 1, 2 and 3.

Extension Activity

The Rainfall Disaster Warning Simulator (RDWS) is being further developed. The main() function now looks like this:

static int rainfall;

public static void main(String[] args){

generateRainfall();

if(rainfall>100){

actionStations();

}

}

Using your own ideas, design the actionStations() helper function.

It should include some or all of the following:

  • use of local variable(s)
  • use of global variable(s)
  • use of function call(s)
  • random number(s)
  • selection statements
  • comments

Helper Video

Tags

iterateauto-indent variablecompile sum machine code count-controlled loop integer pseudocodesyntax