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

Thread: Coding Theory

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Coding Theory

    Here's my problem: I know what it is I need to do for the project. I have no idea how to implement this using code. We have to create a Connect Four game and I know that I am going to need the Scanner class for imputs, arrays, and an enum class. The thing is, how do I go about coding this? When it comes to methods, I know what I need to do, I just don't know how to do it. Any tips on how to turn my ideas into code?

    For reference this is the project. http://www.csee.umbc.edu/courses/und...ects/project2/
    Last edited by Alucard2487; March 10th, 2013 at 07:58 PM. Reason: Spelling/other errors


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

    Default Re: Coding Theory

    So you're unsure of the Java syntax and language/standard API features?

    A good place to start is to look at The Java Tutorials. These go over many different aspects of using the Java platform, including the basic syntax as well as many different parts of the standard API. Look over the Covering the Basics section first to get an understanding of the fundamental syntaxes and classes you'll likely use with Java.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Coding Theory

    Syntax and the standard features are not the problem. It's turning my ideas into code. For example: The ConnectFour object should be able to allow the current player to move, report on whether the game has ended or not, and convert itself to a string for the purpose of display. I get that I need an object that can store the current players move, whether or not they hit Q to end the game, and I think I need to store all of this into another variable. I just don't know how to set up the method itself.

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

    Default Re: Coding Theory

    Start by writing down what you want to do, and how you're going to do it. Go line by line, pretending you're a computer.

    There are many ways to develop code depending on the level of complexity and you're preferences.

    I general like top-down/divide and conquer approaches for larger projects and handling data representation while I do line-by-line for algorithms, program logic, and smaller projects.

    Top-down/divide and conquer approach:

    Block out the key features you need. For example, you know there are players, a board, and pieces. Those sound like good classes so that would be a logical way to divide the data representation. You'll also probably want some sort of game engine type class which operates the game rules and runs the logic.

    Once you have these high-level blocks, pick any one of these and start working your way down. I usually prefer to flush out data representation and manipulation before working on program logic.

    Let's take the player class as an example. The requirements state that players should have a name, so that's something you'll want to include. A player will also have some pieces, so it may make sense to keep track of the player's pieces in the player class, but it isn't necessary. You could also keep track of all the pieces in the board class, you'll need to investigate which of these options makes more sense or is easier to manipulate as far as the game is concerned. Hint: if you're unsure which route is better to pursue, read the instructions. They hint/guide you towards one of these two solutions.

    Once you've finished blocking out the player class, move onto the board class, then the piece class, and then the game engine class until you've roughly flushed out what each class should have and do.

    The next step is to get a rough idea of what the program logic should do. Luckily, the assignment lays out roughly the flow of the game logic so you can start working from there.

    The first step is to get the name of each player. How would you go about accomplishing that? Write down line by line the process for doing that. Then move onto the next step. FYI, this is the line-by-line approach.

    Note that up to this point you may have not actually written any Java code yet, or you may have a rough class representation with empty methods that have comments describing how they should work and what needs to be done to accomplish that. Now you just need to fill in the blanks with actual code. The more work you put in up-front, the easier this step will be.

    For example:

    public static void main(String[] args)
    {
        // ask player 1 for their name
        // ask player 2 for their name
        // ask for the board size
        // ...
    }

    As you're filling in the code, be sure to test often! One of the listed assignment goals is to use unit tests. These are very helpful for debugging a small section of code to ensure it is functioning as you intended it to. There are various ways to write effective unit tests, you can either write these before writing the actual code or you can write the two together at the same time. You could also write these afterwards, but I find these tend to be somewhat less effective in general (but not always). Also don't be afraid to re-run old tests as you code in other sections. This is done to ensure that whatever new code you wrote doesn't break the old code. Usually this isn't terribly important if your unit tests test code that's run completely independent from other code, but sometimes it's very difficult or impossible to decouple code from everything else so changing code in one place may affect how some other code runs.

    If you need help figuring out how to fill in any of these individual sections, ask about them specifically, or better yet use your favorite internet search engine.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Coding Theory

    This advice makes the most sense out of everything I've read. I think my main problem is that I want to do everything at once. Building a skeleton of the classes and methods makes way more sense. Thank you so much!

Similar Threads

  1. Casting Theory
    By BigDru in forum Java Theory & Questions
    Replies: 1
    Last Post: October 25th, 2012, 09:21 AM
  2. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  3. More number theory
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 13th, 2012, 01:49 AM
  4. Theory/Question,
    By Time in forum Java Theory & Questions
    Replies: 7
    Last Post: November 9th, 2010, 05:26 PM
  5. Theory Inquiry
    By b_jones10634 in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 19th, 2010, 09:21 AM