Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. /**
  4.  * Write a description of class GCNewForest here.
  5.  *
  6.  * @author (your name)
  7.  * @version (a version number or a date)
  8.  */
  9. public class NewForest
  10. {
  11.     // instance variables - replace the example below with your own
  12.     private Tree[][] trees;
  13.     private int n;
  14.  
  15.     /**
  16.      * Constructor for objects of class NewForest
  17.      */
  18.     public NewForest()
  19.     {
  20.         // initialise instance variables
  21.         n = 4;
  22.         // Setting up an array of 4 rows and 4 columns.
  23.         Tree[][] trees = new Tree[4][4];
  24.         // Adding trees into the 2D array.
  25.         for (int i = 0; i < trees.length; i++)
  26.         {
  27.             for (int j = 0; j < trees.length; j++)
  28.             {
  29.                 if ((i+j)%2 == 0)
  30.                    trees[i][j] = new Ash();
  31.                
  32.                 else
  33.                    trees[i][j] = new Beech();
  34.             }
  35.         }
  36.     }
  37.    
  38.     public Tree getTree(int i, int j)
  39.     {
  40.         if(i < 4 && j < 4)
  41.         {
  42.             Tree trees = Tree[i][j];
  43.         }
  44.            
  45.         else
  46.         {
  47.             return null;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement