-
hi
Hi,
I am new to java and I am trying to learn java using the head first java II Edition. I am using Eclispse. For certain practise programs when I want to run it as a java application, that option is not coming. Only option that comes is run in server. Please help me understand why is it so. The program which I am not able to run as java application is posted below.
public class game {
public class gamelauncher {
public void main (String[] args) {
gamestart g = new gamestart();
g.play();
}
}
public class player {
int playerno;
public int playerass() {
playerno=(int)(Math.random()*9);
return playerno;
}
}
public class gamestart {
int prize;
boolean t = false;
public void playno()
{
prize=(int)(Math.random()*9);
System.out.println("system has selected a value");
}
public void play() {
while (true) {
player ply1 = new player();
player ply2 = new player();
player ply3 = new player();
int a;
int b;
int c;
a= ply1.playerass();
b= ply2.playerass();
c= ply3.playerass();
boolean ply1rite = false;
boolean ply2rite = false;
boolean ply3rite = false;
if (a==prize) {
ply1rite = true;
}
if (b==prize) {
ply2rite = true;
}
if (c==prize) {
ply3rite = true;
}
if (ply1rite || ply2rite || ply3rite) {
System.out.println("player has guessed the number");
break;
}
}
}
}
}
-
Quote:
I am not able to run
Does it compile?
Do you get errors? It looks like you should get some.
How are you executing it? via a Commandline or ?
Open a command prompt, change to folder with class file and enter: java gamelauncher
-
Seems to me too, you must comes with some errors when you compiling that code.
You have to learn a lot about Java lol.
Firs of all, you cannot define more than one public class on a same file(Java file). Better to find the reason by yourself. And how to define a main method.
Best thing is you should explain well about your question. Start to work on step by step.