# guess the number game

Page 1 of 1

## 12 Replies - 1469 Views - Last Post: 13 December 2009 - 09:10 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=145265&amp;s=74b5ef7c78ecbd3956b9f4466346586d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Nameo0

Reputation: -10
• 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

Reputation: 6
• 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

### #3 Nameo0

Reputation: -10
• 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

### #4 sabriath

Reputation: 6
• 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

### #5 Nameo0

Reputation: -10
• 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

### #6 Juan1988

Reputation: 1
• 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:
{
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.

### #7 Nameo0

Reputation: -10
• 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);
}
}

### #8 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12241
• Posts: 45,327
• 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;
}

### #9 Nameo0

Reputation: -10
• 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);
}
}

### #10 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12241
• Posts: 45,327
• 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.

### #11 Nameo0

Reputation: -10
• 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?

### #12 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12241
• Posts: 45,327
• 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.

### #13 pbl

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

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

## Re: guess the number game

Posted 13 December 2009 - 09:10 PM

Duplicated topics merged