Results 1 to 5 of 5
  1. #1
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default Stuck - simple program

    Hi guys im trying to create a simple card game. This is the last class i need to create in order for my assignment
    to be finished and im very stuck!
    Here are my instructions -


    The Game class has two elds representing Player one and Player two.
    The constructor for this class has two parameters which are the names of the two players. The
    constructor will initialise the two fields.
    The Game class has a single method called play which has no parameters and does not return
    a value. This method should print out a suitable introduction and then:

    1. Instruct player one to play first. The instruction should give the name of player one.
    so something like system.out.println("Player One needs to go first") but how to i call the getName method i have
    which is in another class and connect it here?
    2. Invoke the play method of Player one.
    this bit i dont understand, because there is simply one play method right? The instructions dont indicate 2 seperate
    play methods for each player?
    3. Announce the score for Player one.
    Simply again, im not sure how to call a method which is in another class.

    any input would be appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    It's hard to know what's going on without code, but from what you've told us and my crystal ball, we know that Game has two Player objects. It may also have a variable which tells us which Player's turn it is.

    I would think that Game will get the Player's name by calling a getName() method or something similar on the Player whose turn it is. Does Player have such a method?

    While Game has only one play() method, I would assume that the Player class also has a similarly named method. This is the one that Game will call repeatedly on alternating players (when you hear "repeatedly" in programming -- think loop). So while you're right there is only one play() method for game, you're not calling this on the players but instead are calling their own play() methods.

    To call a method on a Player class simply do something like player1.play();

  3. #3
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    Are you sure a loop is needed?

    Java Code:
       private void play()
        {
            printWelcome();
            player1.getName();
            System.out.println("You're player one, its your turn first");
            player1.play();
            player1.getScore();
            player2.getName();
            System.out.println("You're player two, its your turn next");
            player2.play();
            player2.getScore();
           
            
            
        }
    so something like that would be wrong?
    Last edited by dirtycash; 11-24-2008 at 03:31 PM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Am I sure about a loop? Heck no. It's your program and none of us know much about the program or requirements, so I'm sure about nothing.

    If the players will only do one turn each, then no loop is needed. If the players need to play until a certain score is reached or a certain number of turns are played then you'll likely need a loop of some format or another.

    Your code looks OK on first glance, but I am a little concerned that you get the player's score but don't do anything with them such as store them in a variable and then display them.

  5. #5
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    getting help else where.
    Last edited by dirtycash; 11-24-2008 at 09:11 PM.

Similar Threads

  1. Really Stuck on how to Start this program
    By random0munky in forum New To Java
    Replies: 4
    Last Post: 10-29-2008, 08:57 AM
  2. Replies: 8
    Last Post: 08-26-2008, 04:50 AM
  3. FireSimulation Program, got stuck with a bug...
    By riz618 in forum New To Java
    Replies: 5
    Last Post: 01-28-2008, 03:48 PM
  4. help with simple program in java
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM
  5. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 09:40 AM

Posting Permissions

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