• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Cant compile GameLauncher.java

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I have some problem. Can't compile file, - error 72 ";" after word "game"

GuessGame game^ - new GuessGame();


 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you have in your code.

Replace it with
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dmitriy Birukov wrote:GuessGame game^ - new GuessGame();


Well that's not valid Java code. It should be something like
 
Dmitriy Birukov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not my code. This is part from code in book "First Head Java second edition, page 40).

I am just looking there. Here is full version of code i have 1 on 1 with book version, if i am not blind )

Sorry for that words in code, they are mine))

public class GuessGame {
Player p1;
Player p2;
Player p3;

public void startGame() {
p1 = new Player();
p2 = new Player();
p3 = new Player();

int guessp1 = 0;
int guessp2 = 0;
int guessp3 = 0;

boolean p1isRight = false;
boolean p2isRight = false;
boolean p3isRight = false;

int targetNumber = (int) (Math.random() * 10);
System.out.println("ja zagadivaiu chislo ot 0 do 9...");

while(true) {
System.out.println("Chislo kotoroe nuzhno ugadat,- " + targetNumber);

p1.guess();
p2.guess();
p3.guess();

guessp1 = p1.number;
System.out.println("perviy igrok dumaet, chto eto " + quessp1);
guessp2 = p2.number;
System.out.println("vtoroi igrok dumaet, chto eto " + guessp2);
guessp3 = p3.number;
System.out.println("tretiy igrok dumaet, chto eto " + guessp3);


if (guessp1 = targetNumber) {
p1isRight = true;
}
if (guessp2 = targetNumber) {
p2isRight = true;
}
if (guessp3 = targetNumber) {
p3isRight = true;
}

if (p1isRight || p2isRight || p3isRight) {

System.out.println("u nas est pobeditel!");

} else {

System.out.println("igroki dolgni poprobovat esche raz");
}
}
}
}



public class Player {
int Number = 4;
public void quess() {
number = (int) (Math.random() * 10);
System.out.println("dumaiu, eto chislo" + number);
}
}

public class GameLauncher {
public static void main (String[] args) {

GuessGame game - new GuessGame() ;
game.startGame() ;
}
}
 
Dmitriy Birukov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me, still cant compile

What wrong in that code?

Why he ask me to put ";" after "game" . Actually, i just copy text from book, and still have that problem.
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have some poor quality scan or is this book so bugged?

First, as I said, the expression
GuessGame game - new GuessGame() ;
is invalid.

Replace it with
GuessGame game = new GuessGame() ;

Second,
Don't use = operator in if statement. Use == instead

This is wrong:


This is ok:
 
Dmitriy Birukov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, i am an idiot... Sorry please, really blind. Thank you very much.

 
Dmitriy Birukov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused

class TapeDeck {
boolean canRecord = false;
void playTape() {
System.out.println(“tape playing”);
}
void recordTape() {
System.out.println(“tape recording”);
}
}


C:\Java>javac TapeDeckTestDrive.java
TapeDeckTestDrive.java:8: error: cannot find symbol
t.playtype();
^
symbol: method playtype()
location: variable t of type TapeDeck
1 error

C:\Java>

Hey guys, how you take out my code in a separate window? Very comfortable.
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dmitriy Birukov wrote:C:\Java>javac TapeDeckTestDrive.java
TapeDeckTestDrive.java:8: error: cannot find symbol
t.playtype();
^
symbol: method playtype()
location: variable t of type TapeDeck
1 error



That means exactly what it says. The compiler can't find variable t because you didn't declare one.
You might have declared variable named t somewhere but in such case it is out of scope.

Sorry, this error means that class TapeDeck doesn't have method playtype visible from TapeDeckTestDrive class.
Is it in another package?
And... you didn't post source code of TapeDeckTestDrive class.
Right now I have to guess.

Dmitriy Birukov wrote:Hey guys, how you take out my code in a separate window? Very comfortable.


Mark the code you pasted and press "Code" button while editing your post.
UseCodeTags <- click this
 
Dmitriy Birukov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ah thank you. I did spelling error (PlayTape > playtype) . Oh... my mistakes dement me.
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic