Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-16-2008, 02:42 AM
Member
 
Join Date: May 2008
Posts: 9
CrazyShells Slam is on a distinguished road
Extra bracket
Im getting an error that bluej is expecting a bracket to be at the beginning of a class, however all brackets are in place and accounted for....IM a bit confused?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-16-2008, 03:28 AM
Member
 
Join Date: May 2008
Posts: 9
CrazyShells Slam is on a distinguished road
Heres the code I currently have laid out

Code:
import java.util.Scanner; import java.util.Random; public class Tic Tac Toe { public static void main(String[] args) { Scanner keyboard=new Scanner(System.in); String[][] board= {{" "," "," "},{" "," "," "},{" "," "," "}}; int x=0; int y=0; int option=0; String player1; String player2; System.out.println("Press 1 for 2 players, or press 7 to exit"); option=keyboard.nextInt(); if (option==1) { System.out.println("Player 1 enter your name"); player1=keyboard.next(); System.out.println("Player 2 enter your name"); player2=keyboard.next(); boolean w=winner(board); while (w==true||w==false) { System.out.println(player1+"Enter your choice"); x=keyboard.nextInt(); y=keyboard.nextInt(); if (board[x][y]=="X") { System.out.println("That space is already taken"); continue; } if (board[x][y]=="Y"){ System.out.println("That space is already taken"); continue; } board[x][y]="X"; displayBoard(board); do { System.out.println(player2+" enter your choice"); x=keyboard.nextInt(); y=keyboard.nextInt(); if (board[x][y]=="X") { System.out.println("That space is already taken"); continue; } if (board[x][y]=="O") { System.out.println("That space is already taken"); continue; } board[x][y]="O"; displayBoard(board); break; } while (true); } } } public static void displayBoard (String z[][]) { System.out.println(" "+z[0][0]+" | "+z[0][1]+" | "+z[0][2]); System.out.println(" ---------"); System.out.println(" "+z[1][0]+" | "+z[1][1]+" | "+z[1][2]); System.out.println(" ---------"); System.out.println(" "+z[2][0]+" | "+z[2][1]+" | "+z[2][2]); } public static boolean winner (String z[][]) { if ( ( z[0][0]=="X" && z[0][1]=="X" && z[0][2]=="X" ) || ( z[1][0]=="X" && z[1][1]=="X" && z[1][2]=="X" ) || ( z[2][0]=="X" && z[2][1]=="X" && z[2][2]=="X" ) || ( z[0][0]=="X" && z[1][0]=="X" && z[2][0]=="X" ) || ( z[0][1]=="X" && z[1][1]=="X" && z[2][1]=="X" ) || ( z[0][0]=="X" && z[1][1]=="X" && z[2][2]=="X" ) || ( z[0][2]=="X" && z[1][1]=="X" && z[2][0]=="X" ) ) { return true; } } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 05:29 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 227
Eku is on a distinguished road
Your Program still has lots of Buggs. Like the game doesnt end. Try using Swing =)

The winner function doesnt have a return statement if the 'if' function is not satisfied. Remember to put default values if the 'if' condition is not satisfied. =)
Code:
public static boolean winner (String z[][]){ if ( ( z[0][0].equalsIgnoreCase("X") && z[0][1].equalsIgnoreCase("X") && z[0][2].equalsIgnoreCase("X") ) || ( z[1][0].equalsIgnoreCase("X") && z[1][1].equalsIgnoreCase("X") && z[1][2].equalsIgnoreCase("X") ) || ( z[2][0].equalsIgnoreCase("X") && z[2][1].equalsIgnoreCase("X") && z[2][2].equalsIgnoreCase("X") ) || ( z[0][0].equalsIgnoreCase("X")&& z[1][0].equalsIgnoreCase("X")&& z[2][0].equalsIgnoreCase("X") ) || ( z[0][1].equalsIgnoreCase("X") && z[1][1].equalsIgnoreCase("X")&& z[2][1].equalsIgnoreCase("X") ) || ( z[0][0].equalsIgnoreCase("X") && z[1][1].equalsIgnoreCase("X") && z[2][2].equalsIgnoreCase("X") ) || ( z[0][2].equalsIgnoreCase("X") && z[1][1].equalsIgnoreCase("X") && z[2][0].equalsIgnoreCase("X") ) ) {return true;} else {return false;} }
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-16-2008, 05:30 AM
Member
 
Join Date: May 2008
Posts: 9
CrazyShells Slam is on a distinguished road
Ive been taking different approaches and what not, I changed the code a bit so Im like a couple of steps ahead
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-16-2008, 07:31 AM
Member
 
Join Date: May 2008
Posts: 9
CrazyShells Slam is on a distinguished road
Alright so I made the necessary corrections, but I still have the bracket errror

Code:
public class Tic Tac Toe { public static void main(String[] args) { Scanner keyboard=new Scanner(System.in); String[][] board= {{" "," "," "},{" "," "," "},{" "," "," "}}; int x=0; int y=0; int option=0; String player1; String player2; System.out.println("Press 1 for 2 players, or press 7 to exit"); option=keyboard.nextInt(); if (option==1) { System.out.println("Player 1 enter your name"); player1=keyboard.next(); System.out.println("Player 2 enter your name"); player2=keyboard.next(); boolean w=winner(board); while (w==true||w==false) { System.out.println(player1+"Enter your choice"); x=keyboard.nextInt(); y=keyboard.nextInt(); if (board[x][y]=="X") { System.out.println("That space is already taken"); continue; } if (board[x][y]=="Y"){ System.out.println("That space is already taken"); continue; } board[x][y]="X"; displayBoard(board); do { System.out.println(player2+" enter your choice"); x=keyboard.nextInt(); y=keyboard.nextInt(); if (board[x][y]=="X") { System.out.println("That space is already taken"); continue; } if (board[x][y]=="O") { System.out.println("That space is already taken"); continue; } board[x][y]="O"; displayBoard(board); break; } while (true); } } } public static void displayBoard (String z[][]) { System.out.println(" "+z[0][0]+" | "+z[0][1]+" | "+z[0][2]); System.out.println(" ---------"); System.out.println(" "+z[1][0]+" | "+z[1][1]+" | "+z[1][2]); System.out.println(" ---------"); System.out.println(" "+z[2][0]+" | "+z[2][1]+" | "+z[2][2]); } public static boolean winner (String z[][]) { if ( ( z[0][0]=="X" && z[0][1]=="X" && z[0][2]=="X" ) || ( z[1][0]=="X" && z[1][1]=="X" && z[1][2]=="X" ) || ( z[2][0]=="X" && z[2][1]=="X" && z[2][2]=="X" ) || ( z[0][0]=="X" && z[1][0]=="X" && z[2][0]=="X" ) || ( z[0][1]=="X" && z[1][1]=="X" && z[2][1]=="X" ) || ( z[0][0]=="X" && z[1][1]=="X" && z[2][2]=="X" ) || ( z[0][2]=="X" && z[1][1]=="X" && z[2][0]=="X" ) ) { return true; } else {return false;} } }
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-16-2008, 08:12 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Class definition is wrong. You can't leave space in class name. It should be like this,

Code:
public class TicTacToe { // body of the class }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 03:29 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org