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

Thread: Write methods and constructors from Javadocs

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Write methods and constructors from Javadocs

    Hi everyone, I'm currently having an assignment in which my instructors want students to "understand" and interpret Javadocs, then write the methods and constructors back from them. Right now I'm stuck at these last two and I would like to ask you guys for suggestions.

    [B]Constructor Detail[/B]
    DogAndCat
     
    public DogAndCat(int size)
     
        Creates a grid of squares with height and width both equal to the given size; each square is constructed with the appropriate status (cat, dog, or a vacant spot) for starting a game.
     
        The starting configuration consists of a vacant square in the center and the remaining square being half occupied by cats and half occupied by dogs. Each (vertical) column with a higher index than the middle column starts with all cats, and each column with an index lower than the middle column starts with all dogs. The center column has cats in the low row indices, dogs in the high row indices, and a vacant spot in the middle.
     
        The legal range of size is odd numbers from 3 up to 9, which is assumed by the constructor as a precondition.

    and another Javadocs (this time for a method called "isSolved" :

    isSolved
     
    public boolean isSolved()
     
        Indicates whether or not all lily pads in the pond are in the solved state.
     
        Returns:
            true if the puzzle is solved and false otherwise.

    He was asking us to write a cat and dog game, where you can find an example here : Toads And Frogs puzzle in two dimensions (actually the one in the example are frogs and toads, but he changes it to cats and dogs lol). I don't know what to put inside the constructor, as well as "isSolved" method. How could one know when is the problem solved? I'm really confused right now. Any help is appreciated. Thank you.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,537
    My Mood
    Grumpy
    Thanks
    0
    Thanked 166 Times in 157 Posts

    Default Re: Write methods and constructors from Javadocs

    You need to create a size X size 2D array to hold cats or dogs. I assume the rest of the assignment gives details of what cats and dogs are. The instructions go into great detail of which cells in the 2D array will be blank, which hold dogs and which hold cats. What specific part are you having trouble with? Try writing some code. When you get stuck, post the code and any error messages you get and ask a specific question. "I don't know how to do this" is not specific.

    Also, the last line mentions what valid values size can have. You should add some code at the start of the constructor to validate the size. If it is invalid, throw an IllegalArgumentException.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Write methods and constructors from Javadocs

    Thanks for your input ^^, I have already put if else to validate the size. However, I got lost after that because I don't know how to make that size X size 2D array you said above, as well as how to make the "play area" according to what user wants in the main app (for ex if user input 3 it creates a 3x3 area with 9 squares, 5 will be 5x5, 6 will be invalid, 10 will be invalid, and so on). Canyou give me a link on how to make that kind of array please? I got lost right at the start, so I couldn't write any code on the applet yet, except for the validation part

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,537
    My Mood
    Grumpy
    Thanks
    0
    Thanked 166 Times in 157 Posts

    Default Re: Write methods and constructors from Javadocs

    What happened when you typed "java 2d array" into Google?

Similar Threads

  1. How to write this without
    By Scotty in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 21st, 2011, 09:04 AM
  2. [SOLVED] Write an xml dom to a xml file
    By Kakashi in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: March 2nd, 2011, 02:30 PM
  3. How to write server?
    By snytkine in forum Java Networking
    Replies: 4
    Last Post: October 22nd, 2010, 02:25 PM
  4. Array object and constructors
    By TarunN in forum Collections and Generics
    Replies: 14
    Last Post: May 6th, 2010, 04:04 PM
  5. Constructors, Hash Tables, & Linked Lists
    By illusion887 in forum Collections and Generics
    Replies: 2
    Last Post: December 3rd, 2009, 02:46 AM