Here are the new tools you need for your Array quiz

Note: This test will be more cummulative than the prior ones (except for graphics).

Arrays:

Existing Knowledge:

public class MyClassName
{
     // you can define a class variable here
     public static void main( )
     {

           // your statements will go here
           // your calls to method1 will have the form: method1()
     }
     public static void method1( )
     {

           // your statements will go here
     }
}


Loops

For loop - repeats when you know the number of times to repeat


for (statement to start the loop; condition that evaluates to true or false; statement to run when the loop repeats)
{
// do something
}

What you need to know:

FOR coding helps: (but not needed explicitly for the test)

Work with methods



If / if else / else

if (condition that evaluates to true or false)
{
// do something
}
else if (condition that evaluates to true or false) // remember that everything that met first criteria doesn't get here
{
// do something else
}
.
. // repeat else if as needed
.
else // remember to put no condition
{
// do something
}

If facts:


Random - Random number generating object

import java.util.Random;
create a new Random Generator : Random myGen = new Random();
Ask your random generator for a new random number: int x = myGen.nextInt(5);
Get a random # starting at 0.

While:

While loop - repeats as long as a condition is met

statement to set up so that the first time through the loop it will run
while (test - if it is true, the code in the braces will run)
{
// do something, including changing some variable so the test will be false
}

  • loop control - know how to set up the test you want; make the test  pass the first time; make the test fail sometime during the loop
  • just like a for loop:
    • scope - variables created in a loop are destroyed at the end of the loop
    • only what is in the {} will repeat.
    • to accumulate - initialize a variable before the loop, add to itself during the loop, and then print the total at the end of the loop
      • zero out a variable before the loop (double sum = 0:)
      • add to that variable inside the loop (sum = sum + whateverYouWantToCount;)
      • print the total after the loop (System.out.println(sum);)
    • tracing - be able to trace all variables in the program including the counter. Know that the first time through the loop it executes the starter statement, and every time follwing it executes the incrementer.) From this you can tell how many times a loop will run.

     

do While - repeats, checking the condition after execution of the loop -- will not include on test

  • similar to while loop
  • always executes once
  • checks condition at end of loop instead of beginning

Recursion - a method repeatedly calls itself until some stop condition - winds and unwinds

public static void method(int x)
{
    if (  condition to stop  ) handle bottom of the winding - where you will stop and turn around
    {
          // do something that does not call method again
    }
    else
    {
         // do something and call method passing it a different x
     }
}

To create:

  • Identify the pattern;
  • Identify the end of the pattern (when it should stop repeating), and code that to return a value.
  • Code the pattern to call itself, passing a parameter different than what the method was called with.

Graphic - -- will not ask you to write new code for graphic on test

  • import picture knowledge: javalib.worldimages.*;
  • import color knowledge: java.awt.Color;
  • Make WorldImages using AImage.make<shape> , AImage.makeFromFile
  • Place images on top of each other using <your world image>. place (<your other world image> , x,y)
  • x indicates how far to the right; y indicates how far down (positive)
  • Show your image with <your world image>.show()

    Characters:

    Equality Testing

    Error Handling - Exceptions