Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: nedd help using netBeans to do my assignment

  1. #1
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default nedd help using netBeans to do my assignment

    Create a Tic Tac Toe game. In this game, two players alternate placing Xs and Os
    into a grid until one player has three matching symbols in a row, either horizontally,
    vertically, or diagonally. Create a game in which the user is presented with a threeby-
    three grid containing the digits 1 through 9. When the user chooses a position by
    typing a number, place an X in the appropriate spot.
    Generate a random number for
    the position where the computer will place an O. Do not allow the player or the
    computer to place a symbol where one has already been placed. Figure 9-26 shows
    the first four windows in a typical game. When either the player or computer has
    three symbols in a row, declare a winner; if all positions have been exhausted and no
    one has three symbols in a row, declare a tie. Save the game as TicTacToe.java.

    You are required to develop this game using NETBEANS as the interface.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: nedd help using netBeans to do my assignment

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: nedd help using netBeans to do my assignment

    this.....

    class TicTacToe
    {
    public static void main(String [] args)
    {
    //System.out.println("Welcome! Tic-Tac-Toe is a two player game.");
    //System.out.println("Enter player one's name: ");

    TicTacToeBoard game = new TicTacToeBoard();
    System.out.println(game.toString());

    //int count = 0;


    game.move('x', 1, 3);
    // game.move('o', 1, 1);

    /* while (game.gameWon() !true || count != 9)
    {
    System.out.print(game.move());
    System.out.print(game.isEmpty());
    }*/
    }
    }This is where all the methods are......

    class TicTacToeBoard
    {
    private char [][] board = new char[3][3];
    String b;

    // This a new constructor that creates a tic-tac-toe board
    public TicTacToeBoard()
    {
    for (int rows = 0; rows < board.length; rows++)// creates rows
    {
    for (int columns = 0; columns <board[rows].length;columns++)// creates columns
    {
    //System.out.println("| ");
    board[rows][columns] = ' ';
    //System.out.println(" |\n" );
    }
    }
    }

    // creates a string form of the tic-tac-toe board and allows the user
    // to access it during the game.
    public String toString()
    {
    String b = "";

    // creates a vertical bar at the beginning and the end of each row
    for (int rows = 0; rows < board.length; rows++)
    {
    b += "| ";
    // adds a space for each row and column character in tic-tac-toe board.
    for (int columns = 0; columns < board[rows].length; columns++)
    {
    b += board[rows][columns] + " ";
    }
    b += "|\n";// prints a | space space space | and breaks off to create two new lines.
    }
    return b; // prints the tic-tac-toe board to be accessed by the user.
    }

    String move(char x, int rows, int columns)
    {
    String b = "";

    // creates a vertical bar at the beginning and the end of each row
    for (int r = 0; r < board.length; r++)
    {
    b += "| ";

    for (int c = 0; c < board[r].length; c++)
    {
    b += board[r][c] + " "; //prints 3 spaces on each line.
    // prints string character from user input if row and column not equal to zero
    if (board[rows - 1][columns - 1] >= 0 && board[rows - 1][columns - 1] <= 2 )
    {
    board[rows - 1][columns - 1] = x;// prints character in the specified index from user input
    b += board[rows - 1][columns - 1];// prints out the board and the new character in specified space.
    }
    else if (board[rows - 1][columns - 1] < 0) // makes user pick another choice
    return "ILLEGAL MOVE, TRY AGAIN!";
    // adds a space for each row and column character in tic-tac-toe board.
    }
    b += "|\n";// prints a | space space space | and breaks off to create two new lines.
    }
    return b; // prints the tic-tac-toe board to be accessed by the user.

    }

    // checks if a space character is empty
    void isEmpty(char x, int row, int col)
    {
    if (board [row - 1][col - 1] == ' ')
    board[row - 1][col - 1] = x;
    else // makes user pick another row and column if space character is not empty
    System.out.println("ILLEGAL CHOICE, PICK AGAIN!");
    }
    // checks if game is won
    public boolean gameWon(int row, int col)
    {
    if ((board[2][0] == board[1][1]) && (board[2][0] == board[0][2]))
    return true;
    else if ((board[2][0] != board[1][1]) && (board[2][0] != board[0][2]))
    return false;

    if ((board[2][2] == board[1][1])&& (board[2][2] == board[0][0]))
    return true;
    else if ((board[2][2] != board[1][1])&& (board[2][2] != board[0][0]))
    return false;

    if ((board[0][0] == board[1][0]) && (board[0][0] == board[2][0]))
    return true;
    else if ((board[0][0] != board[1][0]) && (board[0][0] != board[2][0]))
    return false;

    if ((board[0][1] == board[1][1]) && (board[0][1] == board[2][1]))
    return true;
    else if ((board[0][1] != board[1][1]) && (board[0][1] != board[2][1]))
    return false;

    if ((board[0][2] == board[1][2]) && (board[0][2] == board[2][2]))
    return true;
    else if ((board[0][2] != board[1][2]) && (board[0][2] != board[2][2]))
    return false;

    if ((board[0][0] == board[0][1]) && (board[0][0] == board[0][2]))
    return true;
    else if ((board[0][0] != board[0][1]) && (board[0][0] != board[0][2]))
    return false;

    if ((board[1][0] == board[1][1]) && (board[1][0] == board[1][2]))
    return true;
    else if ((board[1][0] != board[1][1]) && (board[1][0] != board[1][2]))
    return false;

    if ((board[2][0] == board[2][1]) && (board[2][0] == board[2][2]))
    return true;
    else
    return false;
    }
    }Here is the template for the whole thing!!!!!

    class TicTacToe
    {
    public static void main (String [] args)
    {
    TicTacToeBoard b = new TicTacToeBoard();

    while (game not over)
    {
    swtich player
    increment turn counter

    until user enters a valid move
    {
    prompt for move
    }

    make move
    b.makeMove (player, row, col);

    print board
    System.out.println(b);
    }

    print outcome
    }
    }


    class TicTacToeBoard
    {
    private char [][] board = ...;

    public TicTacToeBoard()
    {
    initialize board with spaces
    }

    public void makeMove (char c, int row, int col)
    {
    store symbol in specified position
    }

    public boolean isEmpty(int row, int col)
    {
    return true if square is unfilled
    }

    public boolean gameWon()
    {
    check board for a win
    }

    public String toString ()
    {
    return String representation of board
    }

    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: nedd help using netBeans to do my assignment

    Please edit your post and wrap the code in code tags to preserve its formatting.

    Do you have any specific questions about your code?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: nedd help using netBeans to do my assignment

    my problem is generating numbers randomly and designing GUI

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: nedd help using netBeans to do my assignment

    generating numbers randomly
    See the Random class for methods to generate random numbers.

    Designing GUI is a big topic. Can you be more specific?
    How is GUI used in this assignment?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post Re: nedd help using netBeans to do my assignment

    here is a screen shot of this assignment.....java.jpg

  8. #8
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default tic tac toe gui programm

    so i have to code a tic toe game as follows (as shown in screenshot) using netbeans help me im lost
    Attached Images Attached Images

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: tic tac toe gui programm

    We can't work with screenshots of code, assignments, or errors. Screenshots are good for graphics and not for much else.

    Instead, copy and paste your code between code tags, right here in your next post. Don't go back and correct, change, or add code to an earlier post. That just confuses everybody AND the changes will not be obvious so that no one will know that updates were made.

    We also can't help someone with vague problems like, "I'm lost." Ask specific questions, post errors that you don't understand (copied and pasted between code tags, just like your code), and tell us specifically what you need/want help with (nicely, of course.)

    Good luck.

  10. #10
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: tic tac toe gui programm

    Please do not start multiple threads with the same question.
    Threads merged

Similar Threads

  1. Nedd Java help.Randomising Scene time - Animation
    By Vaderico in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 11th, 2013, 09:29 AM
  2. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  3. Netbeans 6.8
    By selmaky in forum Java IDEs
    Replies: 1
    Last Post: May 14th, 2011, 03:08 PM
  4. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  5. Netbeans help
    By [Kyle] in forum Java IDEs
    Replies: 2
    Last Post: September 20th, 2009, 06:32 PM