How would I change the variables in multiple methods with the user input?

Here is my code for a tic tac toe game I have to do for an assignment, it is currently set at the normal 3 x 3, but the teacher what the user to be albe to change these to between 3-5 before they start playing, here is my codeing
import java.util.*;
public class TicTacToe
Constructs an empty board.
private String[][] board;
private static int ROWS = 3;
private static int COLUMNS = 3;
public TicTacToe()
int size = in.nextInt();
board = new String[ROWS][COLUMNS];
// Fill with spaces
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
board[i][j] = " ";
Sets a field in the board. The field must be unoccupied.
@param i the row index
@param j the column index
@param player the player ("x" or "o")
public void set(int i, int j, String player)
if (board[i][j].equals(" "))
board[i][j] = player;
Creates a string representation of the board, such as
|x o|
| x |
| o|
@return the string representation
public String toString()
String r = "";
for (int i = 0; i < ROWS; i++)
r = r + "|";
for (int j = 0; j < COLUMNS; j++)
r = r + board[i][j];
r = r + "|\n";
return r;
I am having a problem figuring out how to change the variables ROWS , COLUMNS to the given user input, it seems easy but i can't really figure out how to do it
thanks ahead of time

import java.util.*;
public class TicTacToe
Constructs an empty board.
private String[][] board;
private static int ROWS = 3;
private static int COLUMNS = 3;
public TicTacToe()
int size = in.nextInt();
board = new String[ROWS][COLUMNS];
// Fill with spaces
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
board[j] = " ";
Sets a field in the board. The field must be unoccupied.
@param i the row index
@param j the column index
@param player the player ("x" or "o")
public void set(int i, int j, String player)
if (board[j].equals(" "))
board[j] = player;
Creates a string representation of the board, such as
|x o|
| x |
| o|
@return the string representation
public String toString()
String r = "";
for (int i = 0; i < ROWS; i++)
r = r + "|";
for (int j = 0; j < COLUMNS; j++)
r = r + board[j];
r = r + "|\n";
return r;
}sorry for not posting code correctyl new to this forums
Thanks for the help but let me rephrase my question, the rows and columns are the same like 3x3, 4x4 ,or 5x5,
-when the program runs it will ask the user for what they want to set the tic tac toe at between 3 - 5.
My question is how do I get the code
Scanner a = new Scanner ( System.in );
System.out.print("Enter the size of the tic tac toe box to be between 3-5 : ");
int sizeTicTacToe = a.next();to change the variables of ROWS COLUMNS
I just want to know of a way to make the users input of sizeTicTacToe to change the variables ROWS & COLUMNS in my toString() and TicTacToe() methods

Similar Messages

  • My email gives 2 sender addresses, it always automatically goes to the one i don't want as my email address, i try to remember to change it. how do i change it to automatically come up with the one I want

    my icloud email gives 2 sender addresses, (icloud.com and me.com) it always automatically goes to the one i don't want (icloud.com) as my email address, i try to remember to change it to (me.com). how do i change it to automatically come up with the one I want (me.com)

    On your iOS device, go to Settings > Mail, Contacts, Calendars > iCloud > Account. Tap Mail, tap Email, then tap the address you want to send from.

  • How to refresh changed data in a plannable template with the Enter Key

    Hi,
    The situation I face is as follows.
    Integrated Planning is being implemented as a tool for budgeting. The user changes a value in a plannable cell on the portal and wishes to see the new updated data by pressing ENTER. Currently we have provided a REFRESH button so that the user gets the desired result.
    Is it possible to see the updated value by pressing ' ENTER' and if so , whats the way around to do it.
    thanks in advance.
    Jaya

    Hey guys,
    I'm interested too in this solution. In BPS there is an additional function described in the HowTo Paper HowTo run planning functions on save and other events
    Now I'm looking for this possibility in IP as well in excel-based IP and web-based IP. For example a copy function should be executed automatically when pushing the enter key.
    Thanks a lot!
    Clemens

  • How would you change the state to the base state?

    How would you change the state to the base state? Its not
    letting me do something like:
    currentState='<Base State>';

    Sorry about the vagueness of that last reply :)
    What I have done now in my code is this:
    viewstack1.addChildAt(loginCanvas,0);
    toggle.selectedIndex = 0;
    However nothing happens at this line of code:
    toggle.selectedIndex = 0;
    but this works:
    toggle.selectedIndex = 1; or ...
    toggle.selectedIndex = 2;
    toggle.selectedIndex = 3;
    toggle.selectedIndex = 4;
    toggle.selectedIndex = 5;
    toggle.selectedIndex = 6;
    The strange thing is that if I have a button on the screen:
    <mx:Button x="10" y="3" label="Button"
    click="toggle.selectedIndex =0"/>
    and the user clicks it the toggle.selectedIndex = 0; works.
    I'm stumped, any ideas?

  • How would you change the default template?

    How would you change the default template?

    Hi,
    what do you mean by changing the default template? Do you want to change the standard BEx web template for all web applications? This can and should be done with transaction SPRO, there you can change it to your own (maybe by copying the standard template and fitting it to your needs).
    With regards,
    Daniel

  • How do change the duration of multiple clips with timestreach?

    All of the options are grayed out.

    AdminID
    What version of Premiere Elements and on what computer operating system?
    Let us assume Premiere Elements 11, 12, or 13 on Windows 7, 8, or 8.1 64 bit for the purpose of an example.
    1. Select all the clip on the Timeline (all at one time) that are being targeted for same duration change.
    2. Right click anywhere in the selection, select Time Stretch, and, then in the Time Stretch dialog, change the duration 00;00;0O;00. (hours; minutes; seconds; frames).
    Do you have one of those versions that I mentioned, making sure to select all the involved clips ahead of time before going
    after Time Stretch?
    Selections
    If you want all the clips on the Timeline, then Edit Menu/Select All
    or
    Hold down the Shift key of the computer main keyboard, and, with the mouse cursor, click on each of the clips to be involved in this duration change
    or
    With the mouse cursor, draw a rectangle around the clips to go into the selection in order to select them
    Any questions or need clarification, please do not hesitate to ask.
    Thank you.
    ATR

  • How I can change this query, so I can display the name and scores in one r

    How I can change this query, so I can add the ID from the table SPRIDEN
    as of now is giving me what I want:
    1,543     A05     24     A01     24     BAC     24     BAE     24     A02     20     BAM     20in one line but I would like to add the id and name that are stored in the table SPRIDEN
    SELECT sortest_pidm,
           max(decode(rn,1,sortest_tesc_code)) tesc_code1,
           max(decode(rn,1,score)) score1,
           max(decode(rn,2,sortest_tesc_code)) tesc_code2,
           max(decode(rn,2,score)) score2,
           max(decode(rn,3,sortest_tesc_code)) tesc_code3,
           max(decode(rn,3,score))  score3,
           max(decode(rn,4,sortest_tesc_code)) tesc_code4,
           max(decode(rn,4,score))  score4,
           max(decode(rn,5,sortest_tesc_code)) tesc_code5,
           max(decode(rn,5,score))  score5,
           max(decode(rn,6,sortest_tesc_code)) tesc_code6,
           max(decode(rn,6,score))  score6        
      FROM (select sortest_pidm,
                   sortest_tesc_code,
                   score,
                  row_number() over (partition by sortest_pidm order by score desc) rn
              FROM (select sortest_pidm,
                           sortest_tesc_code,
                           max(sortest_test_score) score
                      from sortest,SPRIDEN
                      where
                      SPRIDEN_pidm =SORTEST_PIDM
                    AND   sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
                     and  sortest_pidm is not null 
                    GROUP BY sortest_pidm, sortest_tesc_code))
                    GROUP BY sortest_pidm;
                   

    Hi,
    That depends on whether spriden_pidm is unique, and on what you want for results.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
    If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
    Either way, explain how you get those results from that data.
    Always say which version of Oracle you're using.
    It looks like you're doing something similiar to the following.
    Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
    DEPTNO DNAME          LOC           JOB_1   SAL_1 JOB_2   SAL_2 JOB_3   SAL_3
        20 RESEARCH       DALLAS        ANALYST  3000 MANAGER  2975 CLERK    1100
        10 ACCOUNTING     NEW YORK      MANAGER  2450 CLERK    1300
        30 SALES          CHICAGO       MANAGER  2850 CLERK     950On each row, the jobs are listed in order by the highest salary.
    This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
    It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
    SELECT    deptno
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno
                                              ORDER BY          max_sal     DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno
                       ,           e.job
    GROUP BY  deptno
    ;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
    SELECT    deptno, dname, loc                    -- Changed
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno, dname, loc          -- Changed
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno      -- , dname, loc     -- Changed
                                              ORDER BY          max_sal      DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
    GROUP BY  deptno, dname, loc                    -- Changed
    ;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
    By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
    SELECT    deptno, dname, loc
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
                   SELECT    e.deptno, d.dname, d.loc
              ,       e.job
              ,       MAX (e.sal)     AS max_sal
              ,       ROW_NUMBER () OVER ( PARTITION BY  e.deptno
                                           ORDER BY       MAX (sal)     DESC
                                          )       AS rn
              FROM      scott.emp    e
              ,       scott.dept   d
              WHERE     e.deptno        = d.deptno
              AND       e.job                IN ('ANALYST', 'CLERK', 'MANAGER')
                  GROUP BY  e.deptno, d.dname, d.loc
              ,       e.job
    GROUP BY  deptno, dname, loc
    ;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature.

  • How does iCal, or Calendar, order the display of multiple events for the same time?

    I can't for the life of me figure out how iCal orders the display of multiple items at the same time.  Does anyone have a clue?  It's not alphabetical.  It's not according the the order of the calendars in the left pane.  Is it just random?  Any help would be greatly appreciated.

    In the focus lost eventhandling start a thread which does
    the actual handling.
    the new thread waits for a little time (0.1 seconds)
    the click event of the button checks for a thread like the one above and tells it not to execute
    This way you execute the for the lost focus event only if
    the ok button isn't clicked in the same process ... not
    realy good, because it kind of relies on the ordering of threads ... but maybe it still works for you?

  • How do I change custom field description and name on the project fields PDP

    I'm creating a custom PDP for a workflow process and I need to add the folloiwng fields "Project Name" and "Description"
    When I try to create Project Name custom field under server settings I get the following message "The custom field name cannot match the name of any intrinsic fields."
    So I went to the PDP web part Project fields and I found a field named " Project Name". I added it to the Proejct Fields web part, but it displays as "Name".
    How can I change this field that's out of the box? I don't see "Project Name" and "Description" under server settings > Enterprise Custom Fields and Lookup Tables to modify them.
    Thank you

    Hi there,
    Project Name & description fields are internal fields in project server which you cannot view in Enterprise custom fields in PWA. You will not be able to create with the similar name. There is no way to change these fields as far as I know. 
    I would suggest to have the new fields name something like  Project_Name/ ProjName or Project_Description/ProjDescription . 
    Hope that helps.Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

  • How would u change your old apple ID to update apps

    How would u change your old pop up apple Id to update apps

    Apps are forever tied to the ID that was used to purchase them. You'll need to use the password to the old Apple ID to update them or delete them and buy them again under your new Apple ID.
    This is why you don't change Apple IDs if at all possible. If your email changes, you can always update the Apple ID.

  • I have multiple devices with the same cerificate, once I have a an exception for one, FF denys access to the others. I cannot change the certificates, I need to stop FF blocking them.

    I have multiple devices with the same cerificate, once I have an exception for one, FF denys access to the others. I cannot change the certificates, I need to stop FF blocking them.
    == This happened ==
    Every time Firefox opened
    == I attempt to access a web front end on an IBM SVC device

    You can't use the same certificate more than once.
    See also [[Certificate contains the same serial number as another certificate]]

  • ITunes 11... I have multiple artists with the same album name... how do i have them show up as separate albums?

    I have itunes 11 with iTunes Match on 2 Macs and 2 ios devices... I know it all has bugs... but I have been ok.
    I am wondering how to show my library in the column browser view when I have multiple albums with the same names? I have noticed on my ipod in my car that an album titled "Christmas" plays and includes 2 different albums titled christmas... and in itunes it lists them both when not in the artwork view... (I primarily use the column browser to navigate my library.
    Just wondering if anyone else has experienced this/knows how to fix.
    Thanks!

    Various workarounds I can think of which basically involve playing around with tags.  See which meets your needs or come up with others:
    Give the albums slightly different names.  For example, "Greatest Hits" [ABBA]"
    Do the same but do it in the sort album field.
    Add a bogus disc number to different albums.  It may string them together still but at least they will be slightly grouped.

  • How do I apply same adjustments to multiple photos at the same time?

    How do I apply same adjustments to multiple photos at the same time?

    You can't but you can copy the adjustments made on one photo and apply/paste it onto another by:
    1 - Control (right)-clicking one the edited photo in the Edit mode and selecting Copy Adjustsments
    2 - Control-clicking on the next photo and selecting Paste Adjustments.
    OT

  • How do I change an Apple ID payment method to 'None'? I've tried everything and the only solution is to get a new e-mail and start all over again. Any other options?

    How do I change an Apple ID payment method to 'None'? I've tried everything and I found the only solution is to apply all over again with another e-mail address. Any other options?

    Buy an iTunes Music Card and redeem it to your account - the "none" option should be available then.

  • The calendar week view on my iphone 4s starts on a Sunday.  I am synching with outlook on my computer which starts the week view on a Monday which I prefer.  How do I change my iphone calendar view to start the week on a Monday?

    The calendar week view on my iphone 4s starts on a Sunday.  I am synching with outlook on my computer (pc)  which starts the week view on a Monday which I prefer.  How do I change my iphone calendar view to start the week on a Monday?  I am in Australia.
    I have just noticed the other discussion points - mine is set to Australia. 
    Dear Apple - as the day that the week starts on can depend on country and religion - how about making it an option that the user can change????

    I believe the week view on the iPhone is handled by the Region settings in the phone. I am not aware of any other manner to change it, as you can with Outlook.

Maybe you are looking for