Results 1 to 4 of 4
  1. #1
    Veronica91 is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Please check my code

    Hi all,

    Still very new to Java, just wondering if someone can double check my code for any mistakes. All I'm trying to do at this point is initialize an array and populate it with some GameObjects from another class. I did this in the constructor with a 'size' parameter. You will see one of my comments about the initializing of the GameObjects.

    Thanks for reading.

    Java Code:
    public class GameBarriers {		
    
    	// Declaring an array to store 5 GameObjects (circles)
    	private GameObject barriers[];	
    	
    	public GameBarriers(int size)	{			
    		 
    		//Initialising the array with the 5 objects
    		for (int i = 0; i < size; i++)	{
    			this.barriers = new GameObject[size];
    		}		
    		//Is above 'for' loop doing exactly the same as below?
    //			this.barriers[0] = new GameObject();
    //			this.barriers[1] = new GameObject();
    //			this.barriers[2] = new GameObject();
    //			this.barriers[3] = new GameObject();
    //			this.barriers[4] = new GameObject();		
    	}
    	
    	public int getSize()	{
    		int count = 0;	
    		for (int i = 0; i < barriers.length; i++)	{
    			count++;
    		}
    		return count;		
    	}

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: Please check my code

    The best way to check your code is to compile it and run it. They don't charge any money for it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Veronica91 is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Re: Please check my code

    Unfortunately I can't run or compile the code because its part of an assignment where its our job to fix all the errors in 5 classes, which are many. The code I posted is the start of a class I'm writing that needs to 'fit' in with the rest of the code. I was just hoping someone could simply visual inspect it to see if anything stood out as being incorrect. Just wasn't too sure if I had populated the GameObjects into the array correctly.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: Please check my code

    Well, your code initializes an array 'size' times; once is enough; you can replace that second method by a simple 'barriers.length' and the comment above that for-loop doesn't make sense.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. code to refresh and check the code of a webpage..
    By vaggelis in forum New To Java
    Replies: 5
    Last Post: 02-07-2012, 03:21 PM
  2. Code check
    By JustinP in forum New To Java
    Replies: 4
    Last Post: 09-18-2011, 12:07 AM
  3. Code to check if a piece of code is legal.
    By vahshir in forum New To Java
    Replies: 3
    Last Post: 08-30-2010, 05:21 AM
  4. Could you please check my code?
    By Cylab in forum New To Java
    Replies: 2
    Last Post: 08-11-2010, 01:13 PM
  5. can anyone check my code?
    By Harmesh Goyal in forum New To Java
    Replies: 8
    Last Post: 06-29-2010, 06:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •