Results 1 to 3 of 3

Thread: hi

  1. #1
    techie.it19 is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default 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;
    }

    }
    }
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    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

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •