guess the number game

';' expected error in lines 25, 30, 25

Page 1 of 1

12 Replies - 1436 Views - Last Post: 13 December 2009 - 09:10 PM Rate Topic: -----

#1 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

guess the number game

Posted 13 December 2009 - 02:00 PM

import javax.swing.*;
import java.text.*;

class Fermi {
	
	private static final int MAX_NUMBER = 9;
	private static final int MIN_NUMBER = 0;
	
	boolean again = true;
	
	private double num1, num2, num3, gue1, gue2, gue3, cou;
	
	public Fermi () {
		
		num1 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		num2 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		num3 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		cou = 0;
		
		gue1 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your first number." ));
		getGue1( ) {
			return in1;
		}
			
		gue2 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your second number." ));
		getGue2( ) {
			return in2;
		}
		
		gue3 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your first number." ));
		getGue3( ) {
			return in3;
		}
	}
	
	public void ddoer(){
		
		System.out.println ( "\tGuess\t\tHint\t\t\t\tExplanation" );
		
		
		
		do {
									
			if ((gue1 > 9 || gue1 < 0) || (gue2 > 9 || gue2 < 0) || (gue3 > 9 || gue3 < 0)) {
				System.out.println ( "You lose o.O because this is an invalid input." );
			}
			else if ((gue1 <= 9 && gue1 >= 0) && (gue2 <= 9 && gue2 >= 0) && (gue3 <= 9 && gue3 >= 0)) {
			
			//1
			if ( gue1 == num1 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue1 == num2) || ( gue1 == num3 )) {
				System.out.print ( " Fermi " );
			}
			else if (( gue1 != num1) || ( gue1 != num2 ) || ( gue1 != num3)) {
				System.out.print ( " Pico " );
			}
			//2
			if ( gue2 == num2 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue2 == num1) || ( gue2 == num3 )) {
				System.out.print ( " Fermi " );
			}
			else if (( gue2 != num1) || ( gue2 != num2 ) || ( gue2 != num3)) {
				System.out.print ( " Pico ");
			}
			//3
			if ( gue3 == num3 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue3 == num1) || ( gue3 == num2 )) {
				System.out.print ( " Fermi " );	
			}
			else if (( gue3 != num1) || ( gue3 != num2 ) || ( gue3 != num3)) {
				System.out.print ( " Pico " );	
			}
			cou = ( cou + 1 );
			
			System.out.println ( gue1, gue2, gue3 + "\t\t"  );
			}	
		}
		
	while ( gue1 == num1 && gue2 == num2 && gue3 == num3 );
	
	System.out.println ( " It took you " + cou + " tries." );
	}
	
	
}

class ch7Num17 {
	
	public static void main ( String [] args ) {
		
		Fermi in1, in2, in3;
		
		in1 = new Fermi( );
		in1.ddoer( );
		
		in2 = new Fermi( );
		in2.ddoer( );
		
		in3 = new Fermi( );
		in3.ddoer( );
		
		System.exit(0);
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: guess the number game

#2 sabriath  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 26
  • Joined: 13-December 09

Re: guess the number game

Posted 13 December 2009 - 02:10 PM

getGue1( ) {
			return in1;
		}
getGue2( ) {
			return in2;
		}
getGue3( ) {
			return in3;
		}


you never declared the functions, i'm not totally familiar with java, but with c/c++ you'd need an ident:

int getGue1( ) {
			return in1;
		}
int getGue2( ) {
			return in2;
		}
int getGue3( ) {
			return in3;
		}

This post has been edited by sabriath: 13 December 2009 - 02:11 PM

Was This Post Helpful? 0
  • +
  • -

#3 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: guess the number game

Posted 13 December 2009 - 02:13 PM

private double num1, num2, num3, gue1, gue2, gue3, cou;



i identified it a couple lines up
Was This Post Helpful? 0
  • +
  • -

#4 sabriath  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 26
  • Joined: 13-December 09

Re: guess the number game

Posted 13 December 2009 - 02:18 PM

That identified the variables, not the functions, but as I said, I'm not that familiar with java.

This post has been edited by sabriath: 13 December 2009 - 02:22 PM

Was This Post Helpful? 0
  • +
  • -

#5 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: guess the number game

Posted 13 December 2009 - 02:42 PM

i identified them as doubles instead of int but i still get the error
Was This Post Helpful? 0
  • +
  • -

#6 Juan1988  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 13-December 09

Re: guess the number game

Posted 13 December 2009 - 02:49 PM

first - you cant define method in another method/constructor body! You are defining it in class contructor. And also you must remember you need to declare what will function returns.
for example if you write:
int add(int a,int b)
{
return a+b
}


then compilator will know that you want to add 'a' and 'b' and it will be returned as integer.

You also want to access 'in1' which isn't field in class Fermi. You must declare these methods in class ch7Num17 body.
Was This Post Helpful? 0
  • +
  • -

#7 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: guess the number game

Posted 13 December 2009 - 05:30 PM

i get an ";" expected error in lines 36, 41, 46
please explain in as much detail as possible because i am new to java prog

import javax.swing.*;
import java.text.*;

class Fermi {
	
	private static final int MAX_NUMBER = 9;
	private static final int MIN_NUMBER = 0;
	
	boolean again = true;
	
	private double num1, num2, num3, gue1, gue2, gue3, cou;
	
	public Fermi () {
		
		num1 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		num2 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		num3 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		cou = 0;
		gue1 = 0;
		gue2 = 0;
		gue3 = 0;		
	
	}
	
	public void ddoer(){
		
		System.out.println ( "\tGuess\t\tHint\t\t\t\tExplanation" );		
		
		do {
			
			double gue1 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your first number." ));
			getGue1( ) {
				return in1;
			}
			
			double gue2 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your second number." ));
			getGue2( ) {
				return in2;
			}
		
			double gue3 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your first number." ));
			getGue3( ) {
				return in3;
			}
									
			if ((gue1 > 9 || gue1 < 0) || (gue2 > 9 || gue2 < 0) || (gue3 > 9 || gue3 < 0)) {
				System.out.println ( "You lose o.O because this is an invalid input." );
			}
			else if ((gue1 <= 9 && gue1 >= 0) && (gue2 <= 9 && gue2 >= 0) && (gue3 <= 9 && gue3 >= 0)) {
			
			//1
			if ( gue1 == num1 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue1 == num2) || ( gue1 == num3 )) {
				System.out.print ( " Fermi " );
			}
			else if (( gue1 != num1) || ( gue1 != num2 ) || ( gue1 != num3)) {
				System.out.print ( " Pico " );
			}
			//2
			if ( gue2 == num2 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue2 == num1) || ( gue2 == num3 )) {
				System.out.print ( " Fermi " );
			}
			else if (( gue2 != num1) || ( gue2 != num2 ) || ( gue2 != num3)) {
				System.out.print ( " Pico ");
			}
			//3
			if ( gue3 == num3 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue3 == num1) || ( gue3 == num2 )) {
				System.out.print ( " Fermi " );	
			}
			else if (( gue3 != num1) || ( gue3 != num2 ) || ( gue3 != num3)) {
				System.out.print ( " Pico " );	
			}
			cou = ( cou + 1 );
			
			System.out.println ( gue1, gue2, gue3 );
			}	
		}
		
	while ( gue1 == num1 && gue2 == num2 && gue3 == num3 );
	
	System.out.println ( " It took you " + cou + " tries." );
	}
	
	
}

class ch7Num17 {
	
	public static void main ( String [] args ) {
		
		Fermi in1, in2, in3;
		
		in1 = new Fermi( );
		in1.ddoer( );
		
		in2 = new Fermi( );
		in2.ddoer( );
		
		in3 = new Fermi( );
		in3.ddoer( );
		
		System.exit(0);
	}
}


Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12149
  • View blog
  • Posts: 45,169
  • Joined: 27-December 08

Re: guess the number game

Posted 13 December 2009 - 05:51 PM

Your error lies in the lines where you declare your getGue1() method definitions. Since you cannot declare methods in loops, Java sees these as method calls. The first thing it checks for is that your method call ends in a semi-colon, which it does not, so you get an error. Also, methods that are not constructors must be declared with a return-type.
getGue1( ) {
				return in1;
			}


Was This Post Helpful? 0
  • +
  • -

#9 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: guess the number game

Posted 13 December 2009 - 07:51 PM

i get a not a statement error in lines 24, 29, 34
please explain to me in plain english and as most detail as possible in how to fix this

import javax.swing.*;
import java.text.*;

class Fermi {
	
	private static final int MAX_NUMBER = 9;
	private static final int MIN_NUMBER = 0;
	
	boolean again = true;
	
	private double num1, num2, num3, gue1, gue2, gue3, cou;
	
	public Fermi () {
		
		num1 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		num2 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		num3 = (double) ( Math.floor( Math.random( ) * ( MAX_NUMBER - MIN_NUMBER + 1 )) + MIN_NUMBER );
		cou = 0;
		double gue1 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your first number." ));
		getGue1;
			return in1;
		
		double gue2 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your second number." ));
		getGue2;
			return in2;
			
		double gue3 = Double.parseDouble( JOptionPane.showInputDialog ( null, "Input your first number." ));
		getGue3;
			return in3;
			
	}
	
	public void ddoer(){
		
		System.out.println ( "\tGuess\t\tHint\t\t\t\tExplanation" );		
		
		do {
			
			
									
			if ((gue1 > 9 || gue1 < 0) || (gue2 > 9 || gue2 < 0) || (gue3 > 9 || gue3 < 0)) {
				System.out.println ( "You lose o.O because this is an invalid input." );
			}
			else if ((gue1 <= 9 && gue1 >= 0) && (gue2 <= 9 && gue2 >= 0) && (gue3 <= 9 && gue3 >= 0)) {
			
			//1
			if ( gue1 == num1 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue1 == num2) || ( gue1 == num3 )) {
				System.out.print ( " Fermi " );
			}
			else if (( gue1 != num1) || ( gue1 != num2 ) || ( gue1 != num3)) {
				System.out.print ( " Pico " );
			}
			//2
			if ( gue2 == num2 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue2 == num1) || ( gue2 == num3 )) {
				System.out.print ( " Fermi " );
			}
			else if (( gue2 != num1) || ( gue2 != num2 ) || ( gue2 != num3)) {
				System.out.print ( " Pico ");
			}
			//3
			if ( gue3 == num3 ) {
				System.out.print ( " Nano " );
			}
			else if (( gue3 == num1) || ( gue3 == num2 )) {
				System.out.print ( " Fermi " );	
			}
			else if (( gue3 != num1) || ( gue3 != num2 ) || ( gue3 != num3)) {
				System.out.print ( " Pico " );	
			}
			cou = ( cou + 1 );
			
			System.out.println ( gue1, gue2, gue3 );
			}	
		}
		
	while ( gue1 == num1 && gue2 == num2 && gue3 == num3 );
	
	System.out.println ( " It took you " + cou + " tries." );
	}
	
	
}

class ch7Num17 {
	
	public static void main ( String [] args ) {
		
		Fermi in1, in2, in3;
		
		in1 = new Fermi( );
		in1.ddoer( );
		
		in2 = new Fermi( );
		in2.ddoer( );
		
		in3 = new Fermi( );
		in3.ddoer( );
		
		System.exit(0);
	}
}


Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12149
  • View blog
  • Posts: 45,169
  • Joined: 27-December 08

Re: guess the number game

Posted 13 December 2009 - 07:54 PM

In the statement getGue1; you are only citing a variable name, albeit one that doesn't exist, which isn't a statement. You cannot just cite a variable by itself.
Was This Post Helpful? 0
  • +
  • -

#11 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: guess the number game

Posted 13 December 2009 - 07:59 PM

can u please tell me how to fix it?
Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12149
  • View blog
  • Posts: 45,169
  • Joined: 27-December 08

Re: guess the number game

Posted 13 December 2009 - 09:00 PM

I would delete them as they aren't necessary or used in your program and the subsequent return statements in the constructor. Remember, your constructor method can never return values.
Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: guess the number game

Posted 13 December 2009 - 09:10 PM

Duplicated topics merged
Please avoid double posting :angry:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1