Intro. to Programming Workshop - 3

Tutorials

Welcome back to the Intro. to Programming Workshops! This week's workshop will focus on arrays!
The first version of the PokeVentures game source code is now available! Each week, there will be upgrades to the base source code which runs on the libgdx framework. Please feel free to modify the code as you please!

Resources

Setting up Gradle for PokeVentures

The PokeVentures game requires quite a large number of external libraries to be compiled before it can run, so a build tool known as Gradle will help us do the compiling instead of the usual javac.

Instructions

  1. Download the complete distribution of Gradle from: http://gradle.org/
  2. Extract the downloaded .zip file to your desired destination.
  3. Add the <Gradle-install-folder>/bin/ folder to your System Environment Variables Path. (Done the same way as setting up Java on the command-line - Intro. to Programming Workshop 1)

Summary

Arrays

int[] meow;        // type[] name;  
meow = new int[6]; // name = new type[size];  
int[] shortMeow = new int[6]; // Option 1  
int[] specificMeow = {0, 0, 0, 0, 0, 0}; // Option 2  
int[][] meowception;         // type[][] name;  
meowception = new int[2][3]; // name = new type[size1][size2]  
int[][] shortMeowception = new int[2][3];  
int[][] specificMeowception =  
{
  {0, 0, 0},
  {0, 0, 0}
};
int[][] sameAsAboveMeow = {{0, 0, 0}, {0, 0, 0}};  

Exceptions

String[] words = {"Nup", "Yep"}; // Array has size 2  
words[0] = "Poochyena";          // OK  
words[2] = "Skitty";             // ArrayIndexOutOfBoundsException: 2  
String[] words;         // No initial value yet  
words[0] = "Poochyena"; // Causes a NullPointerException