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

Thread: I dunno What I'm Doing :(

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Exclamation I dunno What I'm Doing :(

    I need help, I dunno what Im supposed to do. Everything that needs to be initialized I feel its coming from classes and interfaces that havent been implemented yet :/
    This assignment builds on Program 3. Your system should be organized as follows:

    A package named games. In the package are these types (a type is a class or interface):
    A class named Game. This is an abstract class that can be extended to create classes for specific games that are played on a square board, like checkers, chess, and tic-tac-toe. The Game class has one instance variable that is an object in the Board class. Its methods should be public, but its instance of Board should be default. If it has any other instance variables, they should be private.
    An interface named Moves. It specifies the methods that are to be implemented by the Board class.
    A class named Board that implements Moves. You should be able to use the Board class from the previous assignment with some changes. The Board class and its methods are public, but its variables should be private. In particular, it has an nXn array that represents the game board, and it must be private. The main modifications that you have to make are to allow game pieces of different kinds. For example, in checkers, pieces can be red or black, and they can be regular checkers pieces or kings, giving a total of four kinds of pieces. (You don't need to know what these mean to do this assignment.) Each kind of piece is identified by a unique code. Squares on the game board can be unoccupied or occupied by a single piece of some kind. Use the following codes to indicate the occupancy of a square:
    0: unoccupied
    1: red checker
    2: black checker
    3: red king
    4: black king
    A class named Checkers, which must be a direct subclass of Game. The Checkers class and its methods should be public, but its variables should be private.
    A class named TestCheckers containing a main program that thoroughly tests the Checkers and Board classes. TestCheckers should not be in the package games.


    abstract class Game{
        Game(int n){
            n = 8;
        }
        Game(final Game agame){
           n = agame.n;
        }
        abstract void display(){
            for(int x=0;x < 8;x++)
                {
                    for(int y=0;y < 8;y++)
                    {
                        System.out.print("0");
                    }
                    System.out.println();
                }
            }
        }
     
    Interface Moves{
        void remove(int row, int col);
        void place(int piece, int row, int col);
        int show(int row, int col);
    }
     
     
    class Board{
    	implements Interface Moves;
    	extends abstract class Game;
     
    	public Board(int n){
            	int board[][] = new int [8][8];
            	int value = board[row][col];
        	}
    	public Board(final Board oldboard){}
    	public void remove(int row, int col){
    		if(row > 8)
                		System.exit(1);
           		else if(col > 8)
                		System.exit(1);
           		else if(row < 0)
                		System.exit(1);
           		else if(col < 0)
                		System.exit(1);
           		Board[row][col] = 0;
    	}
    	public void place(int piece, int row, int col){
    		Board[row][col] = 1;
    	}
    	public int show(int row, int col){
    		int value = Board[row][col];
                		if(value == 0){
                    		System.out.println("Your move has been made!");
                		}else if(value = 1 || 2 || 3 || 4){
                    		System.out.println("This space is occupied.");
                		}
    	}
    }
     
     
    class Checkers{
    	extends class Board;
     
    	Checkers(){}
    	Checkers(final Checkers game){}
    	void remove(int row, int col){}
    	void place(int piece, int row, int col){}
    	int show(int row, int col){}
    	void move(int fromrow, int fromcol, int torow, int tocol){}
    	void display(){}
    }
    Last edited by helloworld922; September 28th, 2010 at 09:28 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I dunno What I'm Doing :(

    Please surround your code with highlight tags. If you're unsure on how to do this, see my siggy.

    You're code has some syntax errors in it. You should declare that a class implements or extends another class/interface before the starting curly bracket. As a guideline, also put which class you're extending (if any other than Object) before declaring which interfaces you want to implement. I'm not sure if this is part of the Java syntax, but I know it does work this way and it makes reading your class definition that much easier.

    class Board extends Game implements Moves
    {
       // class definition in here
    }

    You're also attempting to define abstract methods in the class they're in. Abstract methods are not meant to and cannot be defined in that class but rather implementing classes.

    If you're unsure on the Java syntax for inheritance, abstract classes, or interfaces, I would recommend reading your textbook (if you have one), or use Oracle's Java Tutorials. Google is another great tool if you are simply unsure how these concepts can be used and applied (not necessarily to this problem, but similar ones)

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    x3rubiachica3x (September 28th, 2010)