Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: New to java.....

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New to java.....

    All I'm doing is extending a critter class of a 2D game. I managed to get the movement of the critters to work, however, I feel as though this method could be written more "cleanly". Any input or advice to help my progression of the java language would be grateful.

    //
     public Direction getMove() {	
    		this.northCount++;	
    		Direction[] values = Direction.values();
    		Direction directionValues = values[0];
     
    		if(northCount > 5){
    			directionValues = values[2];
    			this.eastCount++;
    		}
     
    		if(eastCount > 5){
    			directionValues = values[1];  
    			this.southCount++;
    		}
     
    		if(southCount > 5){
    			directionValues = values[3];
    			this.westCount++;
    		}
     
    		if(westCount > 5){
    			this.northCount = 1;
    			this.eastCount = 1;
    			this.southCount = 1;
    			this.westCount = 2;
    		}
     
    		return directionValues;
    	}
    //


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: New to java.....

    We have no idea what your code is supposed to actually do, so we can't really critique it. And what do you find "unclean" about your code? Does it work? Does it do what you expected? Then stop worrying.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: New to java.....

    Hello maize. Welcome to the forums.

    This looks OK to me. It may be worth posting all of your code so we have something to compile.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.