Results 1 to 4 of 4
  1. #1
    bm0322 is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default Help with this program?

    I'm writing a Rock Paper scissors lab, and I'm running into an issue with the method i wrote to check for a winner, which is supposed to be returning a String, but NetBeans is giving me a null pointer exception. Here are the method and the code it affects:
    Method:
    Java Code:
    public static String whoWon(char comp, char b)
        {char comp1=comp;
         char bb=b;
        	if(comp1=='R')
            {if(bb=='R')
            	{System.out.println("We Tie");
            	 ties++;
            	 whoswin="tie";}
             else if(bb=='P')
             	{System.out.println("You Win");
             	 humanWins++;
             	 whoswin="human";}
             else if(bb=='S')
             	{System.out.println("I Win");
             	 compWins++;
             	 whoswin="computer";}
            }
            if(comp1=='P')
            {if(bb=='P')
            	{System.out.println("We Tie");
            	 ties++;
            	 whoswin="tie";}
             else if(bb=='S')
             	{System.out.println("You Win");
             	 humanWins++;
             	 whoswin="human";}
             else if(bb=='R')
             	{System.out.println("I Win");
             	 compWins++;
             	 whoswin="computer";}
            }
            if(comp1=='S')
            {if(bb=='S')
            	{System.out.println("We Tie");
            	 ties++;
            	 whoswin="tie";}
             else if(bb=='R')
             	{System.out.println("You Win");
             	 humanWins++;
             	 whoswin="human";}
             else if(bb=='P')
             	{System.out.println("I Win");
             	 compWins++;
             	 whoswin="computer";}
            }
    		return whoswin;
        }
    Main Line Code:
    if((RockPaperScissors.whoWon(moves[w],myMoves[w])).equals("computer"));
                    System.out.println("I Win");
               if((RockPaperScissors.whoWon(moves[w],myMoves[w])).equals("human"));
                    System.out.println("You Win");
               if((RockPaperScissors.whoWon(moves[w],myMoves[w])).equals("tie"));
                    System.out.println("We tie");
    If you could find any flaw in my logic it would be greatly appreciated!!
    Last edited by JosAH; 12-17-2012 at 05:22 AM. Reason: added [code] ... [/code] tags

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Help with this program?

    Please past your code using the [code][/code] tag. It's really hard to read your code.

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

    Default Re: Help with this program?

    Quote Originally Posted by wsaryada View Post
    Please past your code using the [code][/code] tag. It's really hard to read your code.
    I added those tags for the OP.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Help with this program?

    The first thing that catches my eyes is your semicolons at the end of your if statements. They don't belong there. Check the tutorials for if statements and you'll see how yours differ.

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  2. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  3. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  4. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Tags for this Thread

Posting Permissions

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