Results 1 to 3 of 3
Thread: hi
- 10-26-2008, 06:02 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 4
- Rep Power
- 0
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;
}
}
}
}
}
- 10-26-2008, 07:34 PM #2
Does it compile?I am not able to run
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
- 10-27-2008, 03:43 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks