Methods
[Framework practical 3 of 7]


This practical we're going to clean up our main Analyst class, and build some functionality into our Storage class in the form of some methods that replicate last practical's code.


 

Start, as last practical, by copying your Analyst and Storage files to a new directory: GEOG5XXXM\src\unpackaged\framework3 -- keep a copy of the old files in last practical's directory: don't delete them, but work on the new copies.


First, although we haven't had any problems with static yet, let's make our Analyst class work better for the future. We'd start to have issues with the main being static if we had any additional instance variables or methods in this main class, so let's pre-empt this and move all our code into a constructor. Change the class from this:

public class Analyst {

   public static void main (String args[]) {

      // Where all the code is currently.

   }

}

To this (cut and paste all your code to do randomisation etc. into the right place):

public class Analyst {

   public Analyst () {

      // Where all the code should be.

   }

   public static void main (String args[]) {

      new Analyst();

   }

}

Make sure you've got all your brackets in the right place, and recompile. It should still work fine.


Next, go on to Part Two, where we'll make methods to replicate the code we wrote last practical.