Results 1 to 7 of 7
  1. #1
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default Compilation Problem

    I dont get it, like the compiler isn't adding right...


    Java Code:
    package JavaHowToProgram;
    
    import java.util.Random;
    
    public class RandomIntegers 
    {	
    	public static void main( String args[] )
    	{
    		
    		Random randomNumbers = new Random();
    		int face;
    		int face2;
    		int face3;
    		int face4;
    		int sum;
    		int sum2;
    		
    		for ( int counter = 1; counter <= 1; counter++ )
    		{
    			face = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", face );
    			
    			face2 = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", face );
    			
    			face3 = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", face2 );
    			
    			face4 = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", face );
    			
    			sum = face + face2;
    			sum2 = face3 + face4;
    			
    				System.out.printf( "The sum for Player One is %d\n", sum );
    				System.out.printf( "The sum for Player Two is %d\n", sum2 );
    			
    			if ( sum > sum2 )	
    				System.out.println( "Player One has won the game!/n" );
    			if ( sum2 > sum )
    				System.out.println( "Player Two has won the game!\n" );
    			if ( sum == sum2 )
    				System.out.println( "Tie!" );
    			if ( counter % 5 == 0 )
    				System.out.println();
    		}
    	}
    }
    Compiler\/
    {
    72
    72
    2
    72
    The sum for Player One is 74
    The sum for Player Two is 107
    Player Two has won the game!
    }Compiler/\
    Last edited by whosadork; 09-09-2008 at 03:31 AM. Reason: Compiler at bottom...

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default system dot out not matched

    your diagnostics do not match up with your variables,,.....
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I dont get it, like the compiler isn't adding right...
    I haven't looked at your code yet, but if I were asked to bet if this were a compiler error or a bug in your program, I'll put my money on this being your bug.

    Edit: oh yeah. Please read through your code carefully, especially the "face" variables.
    Last edited by Fubarable; 09-09-2008 at 03:37 AM.

  4. #4
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    no i got it, yeah the variables arn't matched up right, thx...
    i cant beleive i didn't find that....

  5. #5
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    the code in bold are the variables i missed...

    Java Code:
    package JavaHowToProgram;
    
    import java.util.Random;
    
    public class RandomIntegers 
    {	
    	public static void main( String args[] )
    	{
    		
    		Random randomNumbers = new Random();
    		int face;
    		int face2;
    		int face3;
    		int face4;
    		int sum;
    		int sum2;
    		
    		for ( int counter = 1; counter <= 1; counter++ )
    		{
    			face = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", [B]face[/B] );
    			
    			face2 = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", [B]face2[/B] );
    			
    			face3 = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", [B]face3[/B] );
    			
    			face4 = 1 + randomNumbers.nextInt( 100 );
    			
    			System.out.printf( "%d\n", [B]face4[/B] );
    			
    			sum = face + face2;
    			sum2 = face3 + face4;
    			
    				System.out.printf( "The sum for Player One is %d\n", sum );
    				System.out.printf( "The sum for Player Two is %d\n", sum2 );
    			
    			if ( sum > sum2 )	
    				System.out.println( "Player One has won the game!\n" );
    			if ( sum2 > sum )
    				System.out.println( "Player Two has won the game!\n" );
    			if ( sum == sum2 )
    				System.out.println( "Tie!" );
    			if ( counter % 5 == 0 )
    				System.out.println();
    		}
    	}
    }

  6. #6
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default Suggestions

    Could i use some suggestions for the game, i know it sucks now but it might get better.

    Java Code:
    package JavaHowToProgram;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class RandomIntegers 
    {	
    	public static void main( String args[] )
    	{
    		
    		Random randomNumbers = new Random();
    		int face;
    		int face2;
    		int face3;
    		int face4;
    		int sum;
    		int sum2;
    		int NumberRoll;
    		String Name;
    		String Name2;
    		
    		for ( int counter = 1; counter <= 1; counter++ )
    		{
    			
    			System.out.printf( "Welcome to a game of really big dice!\nHave Fun!\n\n" );
    			
    			Scanner input = new Scanner( System.in );
    			
    			System.out.printf( "Enter Your name:\n" );
    			Name = input.next();
    			
    			System.out.printf( "Enter your opponents name:\n" );
    			Name2 = input.next();
    			
    			System.out.printf( "Enter how high you want to rolls to go:\n" );
    			NumberRoll = input.nextInt();
    			
    			System.out.printf( "\n%s's Rolls\n", Name );
    			
    			face = 1 + randomNumbers.nextInt( NumberRoll );
    			
    			System.out.printf( "%d\n", face );
    			
    			face2 = 1 + randomNumbers.nextInt( NumberRoll );
    			
    			System.out.printf( "%d\n", face2 );
    			
    			System.out.printf( "%s's Rolls\n", Name2 );
    			
    			face3 = 1 + randomNumbers.nextInt( NumberRoll );
    			
    			System.out.printf( "%d\n", face3 );
    			
    			face4 = 1 + randomNumbers.nextInt( NumberRoll );
    			
    			System.out.printf( "%d\n\n", face4 );
    			
    			sum = face + face2;
    			sum2 = face3 + face4;
    			
    				System.out.printf( "The sum for %s is %d\n", Name, sum );
    				System.out.printf( "The sum for %s is %d\n", Name2, sum2 );
    				
    			if ( sum > sum2 )	
    				System.out.printf( "%s has won the game!\n", Name );
    			if ( sum2 > sum )
    				System.out.printf( "%s has won the game!\n", Name2 );
    			if ( sum == sum2 )
    				System.out.println( "Tie!" );
    			if ( face == face2 )
    				System.out.printf( "%s has rolled the same two numbers, %d, and %d,\n The chances of doing that are %d to 1!\n", Name, face, face2, NumberRoll);
    			if ( face3 == face4 )
    				System.out.printf( "%s has rolled the same two numbers, %d, and %d,\n The chances of doing that are %d to 1!\n\n", Name2, face3, face4, NumberRoll );
    			if ( NumberRoll == 1 )
    				System.out.printf( "" );
    			if ( counter % 5 == 0 )
    				System.out.println();
    		}
    	}
    }
    \/Compiler
    {
    Welcome to a game of really big dice!
    Have Fun!

    Enter Your name:
    Jerry
    Enter your opponents name:
    CPU
    Enter how high you want to rolls to go:
    500

    Jerry's Rolls
    240
    391
    CPU's Rolls
    18
    438

    The sum for Jerry is 631
    The sum for CPU is 456
    Jerry has won the game!

    }/\Compiler

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    Some of your if conditions are mutually exclusive and could be coded as if else if else vs if if if

    And you could add some comments to explain why you are doing something.
    if ( counter % 5 == 0 ) // leave blank every 5 lines
    System.out.println();

Similar Threads

  1. Jasper compilation
    By java_hunter in forum XML
    Replies: 0
    Last Post: 07-16-2008, 04:01 PM
  2. compilation error(version problem?)
    By Ms.Ranjan in forum New To Java
    Replies: 3
    Last Post: 07-11-2008, 05:31 PM
  3. Unresolved compilation problem
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 08:17 PM
  4. Unresolved compilation problem
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:49 PM
  5. compilation issue
    By orchid in forum Eclipse
    Replies: 2
    Last Post: 04-20-2007, 01:51 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
  •