1 / 12

ITK 168 Even more control structures

ITK 168 Even more control structures. Dr. Doug Twitchell 10/11/05. The test. Average: 83.9 Questions?. Using loops in a GUI. StickFigure example Horizontal stick figures Vertical stick figures. switch. switch(wallDir){ case SOUTH: for(int i = 0; i < length; i++){

maia
Download Presentation

ITK 168 Even more control structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITK 168 Even more control structures Dr. Doug Twitchell 10/11/05

  2. The test • Average: 83.9 • Questions?

  3. Using loops in a GUI • StickFigure example • Horizontal stick figures • Vertical stick figures

  4. switch switch(wallDir){ case SOUTH: for(int i = 0; i < length; i++){ Wall wall = new Wall(this, street + i, avenue, pDir); } break; case EAST: for(int i = 0; i < length; i++){ Wall wall = new Wall(this, street, avenue + i, pDir); } break; case WEST: for(int i = 0; i < length; i++){ Wall wall = new Wall(this, street, avenue - i, pDir); } break; default: for(int i = 0; i < length; i++){ Wall wall = new Wall(this, street - i, avenue, pDir); } }

  5. Printing to the console • System.out.println(); • Demo • Demo with switch

  6. Variables • Declaration: type name; • int num; • Assignment: name = value; • num = 5; • Combined: type name = value; • int num = 5;

  7. Variables • Kinds of variables • parameters • public void move(int numTimes){ … • temporary • int numMoves = numTimes; • instance variables (new!!) • private int street; • constants (new!!) • public static final in MAX_MOVES = 20;

  8. Instance Variables • Represent an attribute of a class • color • current street • name • Are declared outside of the methods • Have a visibility modifier

  9. Instance variables – declaring and assigning public class Robot … { private int street; private int avenue; public Robot(…, int aStreet, int anAvenue,…){ this.street = aStreet; this.avenue = anAvenue; } … }

  10. Example – BasketballPlayer

  11. Constants • Never change during the course of a program • Declared at class level • Are declared static and final • Examples: • π • private static final double PI = 3.14159; • number of points per three pointer • private static final int THREE_POINTER_POINTS = 3; • Show example in BasketballPlayer

  12. Types of class level variables

More Related