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 3 of 3

Thread: Hello !

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Hello !

    My name's Adnan Osman ,I'm a student in the University of Prishtina,Kosovo.I'm studying Computer Science and this is my first year.Yesterday our assistant gave us some programming projects, we have to finish them and after finishing them he will grade us.
    I wanted to find people who could help me because I am on my own and I don't know any expert in this field.

    So I will post you my project and I will wait for you ideas and codes.
    Thank you very much for your understating.
    P.S(We didn't learn anything about arrays so this code should be as simple as possible)



    1.
    Write a program that lets two players play a game of tic-tac-toe (noughts and
    crosses). (Hint: the model simulates the game board, whose internal state
    can be represented by three strings, representing the three rows of the board.
    Write methods that can insert a move into the board and check for three-in-
    a-row. (Note: use the charAt and substring methods for strings; see Table 9,
    Chapter 3 for details about substring.)
    It is simplest to build the game for only one player at first; then add a second
    player. Next, revise the game so that the computer can compete against a
    human player. ??

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Hello !

    Hello adnani,

    Welcome to the Java Programming Forums.

    I'm afraid no one will do your homework assignment for you. Please start a new thread in the correct forum and show us the code you have written so far. Show us exactly what you are stuck on and we will do our best to help you move forward with it.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hello !

    can you help me to change these IF and ELSE statements with WHILE or FOR loops on these classes and can we chenge this method
    Integer.parseInt(playerMove)
    with anotherone ?

    import javax.swing.JOptionPane;
    public class Tic
    {
    	public static void main(String[] args)
    	{
    		TicClass t = new TicClass();
    		char one = '1';	//Numbers for matrix.
    		char two = '2';
    		char three = '3';
    		char four = '4';
    		char five = '5';
    		char six = '6';
    		char seven = '7';
    		char eight = '8';
    		char nine = '9';
    		int gameOver = 0;
     
    		System.out.println("[" + one + "] [" + two + "] [" + three + "]");
    		System.out.println("[" + four + "] [" + five + "] [" + six + "]");
    		System.out.println("[" + seven + "] [" + eight + "] [" + nine + "]");
    		System.out.println("");
    		if(gameOver != 1)
    		{
     
    		for (int i = 0; i < 9; i++)				// Game Loop
    		{
     
    			String playerMove = JOptionPane.showInputDialog("Choose a square player: " + t.getPlayer());
    			int choice = Integer.parseInt(playerMove);
     
    			if(choice == 1 && one != 'X'&& one != 'O')			// Checks for valid moves
    			{
    				one = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 2 && two != 'X'&& two != 'O')
    			{
    				two = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 3 && three != 'X'&& three != 'O')
    			{
    				three = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 4 && four != 'X'&& four != 'O')
    			{
    				four = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 5 && five != 'X'&& five != 'O')
    			{
    				five = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 6 && six != 'X'&& six != 'O')
    			{
    				six = t.playerMarker();
    				t.swapPlayers();
    			}
     
    			else if (choice == 7 && seven != 'X'&& seven != 'O')
    			{
    				seven = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 8 && eight != 'X'&& eight != 'O')
    			{
    				eight = t.playerMarker();
    				t.swapPlayers();
    			}
    			else if (choice == 9 && nine != 'X'&& nine != 'O')
    			{
    				nine = t.playerMarker();
    				t.swapPlayers();
    			}
    			else
    			{
    				System.out.println("Invalid Choice");
    				i--;
    			}
     
    			System.out.println("[" + one + "] [" + two + "] [" + three + "]");		// Prints char. board
    			System.out.println("[" + four + "] [" + five + "] [" + six + "]");
    			System.out.println("[" + seven + "] [" + eight + "] [" + nine + "]");
    			System.out.println("");
    																					// Checks for winners
    			if((one == 'O' && four == 'O' && seven == 'O') || (one == 'X' && four == 'X' && seven == 'X'))							//Vertical rows
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    			else if((two == 'O' && five == 'O' && eight == 'O') || (two == 'X' && five == 'X' && eight == 'X'))
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    			else if((three == 'O' && six == 'O' && nine == 'O') || (three == 'X' && six == 'X' && nine == 'X'))
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    			else if((one == 'X' && two == 'X' && three == 'X') || (one == 'O' && two == 'O' && three == 'O'))				//Horizontal rows
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    			else if((four == 'X' && five == 'X' && six == 'X') || (four == 'O' && five == 'O' && six == 'O'))
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    			else if((seven == 'X' && eight == 'X' && nine == 'X') || (seven == 'O' && eight == 'O' && nine == 'O'))
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}																			//Diagonal rows
    			else if((one == 'X' && five == 'X' && nine == 'X') || (one == 'O' && five == 'O' && nine == 'O'))
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    			else if((seven == 'X' && five == 'X' && three == 'X') || (seven == 'O' && five == 'O' && three == 'O'))
    			{
    				gameOver = 1;
    				System.out.println("Game Over!");
    				System.exit(0);
    			}
    		}
     
    		}
    	}
     
    }