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: Placement of code within an application

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Placement of code within an application

    I have an assignment due for my Introduction to Java for which I have written the majority of the foundational code. The assignment is to write the code for text version of a popular logic game. I have written the code for the playing board, populated it with numbers and so on. My question is regarding a reset method which would reset the playing board returning all of values populating the board to their default values. I have written the code for this reset method and it works as a time procedure but I can't figure out where it should be placed within my application and how it redirect the application to start a new game. This reset method is a simple switch statement prompting the user to enter the letter "R" to prompt the resetting of the game. This works fine, displaying a "new" board but ends there not allowing another game to begin. I hope I have provided sufficient information to get a response... Thanks in advance.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: Placement of code within an application

    I'm not entirely sure how to answer. I sort of understand, but without code or a picture or something to give us an idea of exactly what you have and what you are wanting to have, there is only so much help that can be provided.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Placement of code within an application

    Quote Originally Posted by Deprogrammer View Post
    I have an assignment due for my Introduction to Java for which I have written the majority of the foundational code. The assignment is to write the code for text version of a popular logic game. I have written the code for the playing board, populated it with numbers and so on. My question is regarding a reset method which would reset the playing board returning all of values populating the board to their default values. I have written the code for this reset method and it works as a time procedure but I can't figure out where it should be placed within my application and how it redirect the application to start a new game. This reset method is a simple switch statement prompting the user to enter the letter "R" to prompt the resetting of the game. This works fine, displaying a "new" board but ends there not allowing another game to begin. I hope I have provided sufficient information to get a response... Thanks in advance.
    Assuming you have all the values in an array or something, just use a for loop

    for (int x =0 ; x < array.length; x++)
    {
    array[x] = " ";

    }

    As for the not ending, try using a boolean and a while loop together.
    char c = 'c';

    boolean isDone = false;

    while (isDone == false)
    {
    code for game goes here

    c = console.next().charAt(0);
    switch (c)
    {
    case ('R')
    isDone = false;
    reset();
    break;

    default
    isDone = true;
    break;

    }
    }

    Personally, you could have it much better without the switch structure by having

    if (c =='R' || c == 'r')
    {
    isDone = false;
    reset();
    }

    else
    isDone = true;
    Last edited by javapenguin; November 12th, 2010 at 12:49 PM. Reason: Please post code in [highlight=java] code goes here [/highlight] and error messages in [exception]error messages [/exception]

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Placement of code within an application

    Also, if this happens to be due soon, it may or may not be fully answered in time.

    Also, I don't know what data types you are storing. int, float, double, long, short.

    If the board size never changes, try storing the default values in an array of your data type.

    If you don't know what an array is:

    it basically is

    dataType[] arrayName = new dataType[arraySize];

    arraySize must be >= 1.

    Array indexes start at 0 and go to index arraySize - 1.

    the statement that declares the array above only makes a new array, it does not set any of the values at the indexes in the array. You have to do that yourself.

    Its size cannot be decreased or increased once set. You have to copy all the data into another array of a greater size.

     code goes here.

     
     errors go here.  



     
     output and input processes when you actually run it go here. 

    Last edited by javapenguin; November 12th, 2010 at 01:13 PM. Reason: use [console] info [/console] output and input like in Eclpse

  5. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Placement of code within an application

    Thank you for your replies, they were very prompt and helpful. I figured out a very simple solution that had been right under my nose. Thanks!

Similar Threads

  1. Console Application - How to run it?
    By mirzahat in forum AWT / Java Swing
    Replies: 3
    Last Post: November 15th, 2010, 11:21 PM
  2. Quiz application
    By JonoF in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: May 10th, 2010, 06:06 AM
  3. [SOLVED] [help] the application file (.jad) for application does not appear to be the ....
    By ordinarypeople in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: April 4th, 2010, 03:50 AM
  4. Java Application Help...
    By Brian in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: March 25th, 2010, 07:38 AM
  5. Replies: 0
    Last Post: December 3rd, 2009, 03:43 PM