Multidimensional Array/JavaScript Translation help

Hey =)
I have an assignment. The object is to translate whatever the user types into "pirate talk" using a multi-dimensional array. I'm not asking for someone to do the project.. I'm just stuck. He gave us a code in javascript. Our goal was to put this code into a java-applet and make it work. I can't seem to get this piece of javascript code to work to save my neck. =( Basically; I don't know what else I could do to it to get it to read and replace the selected words... I could do it by making a hashmap dictionary method.. I think... but not this array =( and he wants the array.
Here is the original java-script code that he gave us:
  function Translate(text)
    // Returns: a copy of text with English phrases replaced by piratey equivalents
        for (var i = 0; i < PHRASES.length; i++) {
            var toReplace = new RegExp("\\b"+PHRASES[0]+"\\b", "i");
var index = text.search(toReplace);
while (index != -1) {
text = text.replace(toReplace, PHRASES[i][1]);
index = text.search(toReplace);
return text;
}This is my java-applet.. my edited java-script code is under the "actionPerformed" method.import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class PirateTranslator3 implements ActionListener
private JTextArea pirateArea;
private JTextArea englishArea;
String [][] PHRASES = {{"hello", "ahoy"}, {"hi", "yo-ho-ho"}, {"pardon me", "avast"},
{"excuse me", "arrr"},
{"my", "me"}, {"friend", "me bucko"}, {"sir", "matey"},
{"madam", "proud beauty"}, {"miss", "comely wench"},
{"stranger", "scurvy dog"}, {"officer", "foul blaggart"},
{"where", "whar"}, {"is", "be"}, {"the", "th'"}, {"you", "ye"},
{"tell", "be tellin'"}, {"know", "be knowin'"},
{"how far", "how many leagues"}, {"old", "barnacle-covered"},
{"attractive", "comely"}, {"happy", "grog-filled"},
{"nearby", "broadside"}, {"restroom", "head"}, {"restaurant", "galley"},
{"hotel", "fleabag inn"}, {"pub", "Skull & Scuppers"},
{"bank", "buried treasure"}
private static void createAndShowGUI()
PirateTranslator translator = new PirateTranslator();
translator.launch();
public void launch()
JFrame applicationFrame = new JFrame("Talk like a Pirate!");
applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
applicationFrame.getContentPane().setLayout(new BorderLayout());
englishArea = new JTextArea();
englishArea.setPreferredSize(new Dimension(200,200));
applicationFrame.getContentPane().add(englishArea, BorderLayout.NORTH);
JButton button = new JButton("Translate");
button.addActionListener(this);
applicationFrame.getContentPane().add(button, BorderLayout.CENTER);
pirateArea = new JTextArea();
pirateArea.setPreferredSize(new Dimension(200,200));
applicationFrame.getContentPane().add(pirateArea, BorderLayout.SOUTH);
applicationFrame.setSize(600,600);
applicationFrame.setVisible(true);
public void actionPerformed(ActionEvent e)
     String english = englishArea.getText();
     for (int i = 0; i < PHRASES.length; i++ )
          String toReplace = new RegExp("\\b"+PHRASES[i][0]+"\\b", "i");
          String index = english.search(toReplace);
     while (index != -1){
          if (english.charAt(index) >= "A" && english.charAt(index) <= "Z")
          {     english = english.replace(toReplace, Capitalize(PHRASES[i][1])); }
          else
          {     english = english.replace(toReplace, PHRASES[i][1]); }
          index = english.search(toReplace);
public static void main(String[] args)
SwingUtilities.invokeLater(new Runnable(){
     public void run()
          createAndShowGUI();
Any help, hint, or lead in the right direction would be appreciated.
I'm completely stuck.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Here is the cmd prompt error information:
C:\>javac PirateTranslator3.java
PirateTranslator3.java:36: launch() has private access in PirateTranslator
      translator.launch();
                ^
PirateTranslator3.java:76: cannot find symbol
symbol  : class RegExp
location: class PirateTranslator3
                String toReplace = new RegExp("\\b"+PHRASES[0]+"\\b", "i");
^
PirateTranslator3.java:77: cannot find symbol
symbol : method search(java.lang.String)
location: class java.lang.String
String index = english.search(toReplace);
^
PirateTranslator3.java:79: incomparable types: java.lang.String and int
while (index != -1){
^
PirateTranslator3.java:80: charAt(int) in java.lang.String cannot be applied to
(java.lang.String)
if (english.charAt(index) >= "A" && english.charAt(index) <= "Z"
^
PirateTranslator3.java:80: charAt(int) in java.lang.String cannot be applied to
(java.lang.String)
if (english.charAt(index) >= "A" && english.charAt(index) <= "Z"
^
PirateTranslator3.java:81: cannot find symbol
symbol : method Capitalize(java.lang.String)
location: class PirateTranslator3
{       english = english.replace(toReplace, Capitalize(PHRASES[
i][1])); }
^
PirateTranslator3.java:85: cannot find symbol
symbol : method search(java.lang.String)
location: class java.lang.String
index = english.search(toReplace);
^
8 errorsBasically what I'm getting from th is is that a bunch of those commands aren't in Java.. but I don't know what the equivalent words/phrases are in java =(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Applescript to Javascript Translation Help Needed

    I need to have this Applescript translated so I can use on my Windows system.
    Is there anyone out there who could do this for me?
    set pText to ":  The quick brown fox jumps"
    tell application "Adobe InDesign CS6"
        set stylePage to make page at end of active document
        tell stylePage
            set t to make text frame with properties {geometric bounds:{0.5, 0.5, 10.5, 8}}
            set text column count of text frame preferences of t to 2
        end tell
        set s to every paragraph style of active document
        set contents of last insertion point of t to "Paragraph Styles"
        set applied paragraph style of paragraph (count of paragraphs of t) of t to item 2 of s
        repeat with x in s
            set sname to name of x
            set contents of last insertion point of t to return & return & sname & pText
            set applied paragraph style of paragraph (count of paragraphs of t) of t to x
        end repeat
        set c to every character style of active document
        set contents of last insertion point of t to return & return & return & return & "Character Styles"
        set applied paragraph style of paragraph (count of paragraphs of t) of t to item 2 of s
        repeat with i in c
            set cname to name of i
            set contents of last insertion point of t to return & return & cname
            set applied character style of every word of paragraph (count of paragraphs of t) of t to i
        end repeat
    end tell

    Hi,
    #target indesign
    var
              pText = ":  The quick brown fox jumps",
              t = app.activeDocument.pages.add().textFrames.add({geometricBounds: [0.5,0.5,10,8]}),
              s = app.activeDocument.allParagraphStyles,
              c = app.activeDocument.allCharacterStyles,
              sname, cname, k;
    t.textFramePreferences.textColumnCount = 2;
    t.insertionPoints[-1].properties = {contents: "Paragraph Styles", appliedParagraphStyle: s[1]};
    t.parentStory.appliedCharacterStyle = c[0];
    for (k = 0; k < s.length; k++) {
              sname = s[k].name;
              t.insertionPoints[-1].contents = "\r\r" + sname + pText;
              t.words[-1].appliedParagraphStyle = s[k];
    t.insertionPoints[-1].contents = "\r";
    t.insertionPoints[-1].properties = {contents: "\r\r\rCharacter Styles", appliedParagraphStyle: s[1]};
    for (k = 0; k < c.length; k++) {
              cname = c[k].name;
              t.insertionPoints[-1].contents = "\r\r" + cname;
              t.paragraphs[-1].appliedCharacterStyle = c[k];
    enjoy
    Jarek

  • Multidimensional array in jquery class/object

    I'm trying to get into javascript and jquery for a hobby project of mine. Now I've used the last 4 hours trying to find a guide on how to create class objects that can contain the following information
    Identification : id
    Group : group
    Persons : array(firstname : name, lastname : name)
    Anyone know of a tutorial that can show me how to do this?
    I found this page where I can see that an object can contain an array, but it doesn't state whether it is possible to use a multidimensional array.
    And this page just describes the object with normal values.
    Any pointers in the right direction are appreciated.

    There are no classes in JavaScript. It uses a different style of objects and what you found is indeed what you need.
    Well, it might help to think about it as a dynamic, runtime-modifiable object system. An Object is not described by class, but by instructions for its creation.
    Here you have your object. Note that you can use variables everywhere.
    var id = 123;
    var test = {"Identification": id,
    "Group": "users",
    "Persons": [{"firstname":"john", "lastname":"doe"},{"firstname":"jane","lastname":"doe"}]
    This is identical to the following code. (The first one is a lot nicer, though.)
    var id = 123;
    var test = new Object();
    test.Identification = id;
    test["Group"] = "users;
    test.Persons = new Array();
    test.Persons.push({"lastname":"doe","lastname":"john"});
    test.Persons.push({"lastname":"doe","lastname":"jane"});
    As you can see, you can dynamically add new properties to an object. You can use both the dot-syntax (object.property) and the hash syntax (object["property"]) in JavaScript.

  • Multidimensional Array in Indesign?

    Hey guys,
    normally in javascript I can just create a multidimensional array like so:
    myArray = [ [] ];
    and then assign values like this:
    myArray[0][0] = 'item1';
    In extendscript I get the error "undefined is not an object". Is there something I forgot about, or is this just not possible in Indesign?

    I found out it was another problem. The code works like this, but you need to define in the beginning how many arrays are in the array. Otherwise it will throw the "undefined" error.
    points = new Array(object.paths.length);
    for(i = 0 ; i<object.paths.length; i++){
        points[i] = new Array();
    This code works now, as the length of the array is exactly the length you need. And for every key you add another array, to create your two dimensional array on every key.

  • MultiDimensional Array or what????

    Hi Guys
    I have created an xml document that has this structure for
    each child:
    <work>
    <client>Telstar Records</client>
    <titled>Stargate Music.co.uk</titled>
    <thumb>images/thumbs/stargate_sm.jpg</thumb>
    <description>They were an up and coming band, i was a
    designer with a passion for 3d, they met fell in love and a new
    site was born. All it took was four press shots, one promo and a
    lot of imagination</description>
    <images>
    <image>images/large/telstar_sg_01.jpg</image>
    <image>images/large/telstar_sg_02.jpg</image>
    <image>images/large/telstar_sg_03.jpg</image>
    </images>
    <link>
    http://www.4zero1.co.uk/backupsites/stargate/index.html</link>
    </work>
    I have succesfully created buttons and used an associative
    array to compile the info for each button, woooooo aren't i
    clever!!!! I have set up a path to the <images> node, but I
    am stumped as to how i can pull the information from the
    'workImages' variable in my getworkData() function below .
    I need your help, as i would like to create buttons of the
    childnodes named <image> in the xml, above you can see that
    if i was successful i would have three buttons. My problem is
    relating the information to the buttons and making the buttons
    appear. I am not using a for loop as i would like to animate each
    button using a scripted tween. as in the makeButtons() function.
    Do I need to create a multidimensional array? I have included
    my code below, please don't get too lost in it, i hope someone can
    fathom it for me and give me an answer. My associative array is in
    the function getworkData(); My function to create the 'image'
    buttons is called portfolioImageCreator();
    Many thanks
    Jim

    You could use a table of records or a record group. They both achieve similar results but with very different syntax. I am not sure if there is any difference in performance.
    Record groups are good for certain things like lists populated from the database because built-ins are provided for manipulating them. If you are going to do the manipulation programatically, I personally find the syntax for tables of records less cumbersome than record groups. Learning the syntax for tables of records is also likely to be more universally useful to you as they have various uses such as passing data between procedures.
    In your situation the table of records needs to exist throughout the forms session rather than just during the execution of a single pl/sql block. The way to do that is create a program unit which is a package header without a body. Declare the table in there and it can be used throughout the form.
    However, if you only ever want to keep 5 records, it would probably be easier just to have 5 ordinary items in a control block on the null canvas (or global variables). When you want to record your new action just do:
    :item5 := :item4;
    :item4 := :item3;
    :item3 := :item2;
    :item2 := :item1;
    :item1 := :new_stuff;
    You could even construct the above in a loop using
    copy(name_in('item'||i),'item'i+i)
    but with only 5 items to manipulate, is it worth the bother ?
    Whatever method you decide to use, you are not going to get anything simpler than 5 little assignment statements.

  • JNI multidimensional Array and OpenCV

    Hello everybody,
    my first post, so lets go..
    At the moment I am writing my thesis in the filed of automatic image classification. The project is written in Java, but I wanna use the OpenCV library from Intel (http://sourceforge.net/projects/opencvlibrary/) for facedetection.
    So far I managed to call the native method from Java. What I do I parse the path of the image to be analyzed as a string to my C++ programm. The faces are being detected and written into a so called CvSeq (http://www.comp.leeds.ac.uk/vision/opencv/opencvref_cxcore.htm#cxcore_ds_sequences) which holds the coordinates of the rectangles surrounding the found faces. Until now I can only call cvSeq->total which gives me the total number of faces as ints. That integer I return to my java api.
    What I don't know is, how to return a multidimensional array (2 dimensions) where the first dim contains the path as a string to the file and the second dimension 3 integers for x,y coordinates and the lenght of each rectangle.
    Or better, I might know how to return that Array, but not how to create it.
    I know this is somewht OpenCV specific, but maybe someone knows anything. Any little help would be greatly appreciated. Thanks a lot!!!!
    Regards
    Carsten
    attached: JNI source code
    /////////////////////////////////////////// source code ///////////////////////////////////////////////
    #include "cv.h"
    #include "highgui.h"
    #include "cxcore.h"
    #include "cxtypes.h"
    #include "cvaux.h"
    #include "org_kimm_media_image_data_JNIOpenCV.h"
    #include <stdio.h>
    JNIEXPORT jint JNICALL
    Java_org_kimm_media_image_data_JNIOpenCV_getFaces(JNIEnv *env, jobject object, jstring path)
    //declarations
    CvHaarClassifierCascade *pCascade = 0;
    CvMemStorage *pStorage = 0;
    CvSeq *pFaceRectSeq;
    int scale=1;
    jobjectArray recPoints;
    const char *str = env->GetStringUTFChars(path, 0);
    //initializations
    IplImage* pInpImg = cvLoadImage(str, CV_LOAD_IMAGE_COLOR);
    IplImage* small_image = pInpImg;
    pStorage = cvCreateMemStorage(0);
    pCascade = (CvHaarClassifierCascade *)cvLoad
         (("C:/OpenCV/data/haarcascades/haarcascade_frontalface_default.xml"),0, 0, 0 );
    //validaste that everything initilized properly
    if( !pInpImg || !pStorage || !pCascade)
         printf("Initialization failed: %s \n",
              (!pInpImg) ? "didn't load image file" :
              (!pCascade) ? "didn't load Haar Cascade --"
                   "make sure Path is correct" :
              "failed to allocate memory for data storage");
         exit(-1);
    //performance boost through reducing image size by factor 2          
              small_image = cvCreateImage( cvSize(pInpImg->width/2,pInpImg->height/2), IPL_DEPTH_8U, 3 );
    cvPyrDown( pInpImg, small_image, CV_GAUSSIAN_5x5 );
    scale = 2;
    //detect faces in image
    pFaceRectSeq = cvHaarDetectObjects(small_image, pCascade, pStorage,
                                            1.1,                                        //increase search scale by 10% each pass
                                            6,                                        //drop group of fewer than three detections
                                            CV_HAAR_DO_CANNY_PRUNING,          //skip regions unlikely to contain faces
                                                 cvSize(50,50));                         //use XML default for smallest search scale
    //initialize array for location of the faces (HERE IS WHERE I GET INTO TROUBLE!!!!!)
    int x = pFaceRectSeq->total;
    jclass intArrCls = env->FindClass ( "[I" ) ;
    recPoints = env->NewObjectArray ( x, intArrCls, NULL ) ;
    //for(int j = 0; j <= x; j++) {
    //   recPoints[j] = (jintArray)env->NewIntArray(3);
    for(int i=0;i<(pFaceRectSeq ? pFaceRectSeq->total:0); i++)
                                       CvRect* r = (CvRect*)cvGetSeqElem(pFaceRectSeq, i);
                                       CvPoint pt1 = {(r->x)*scale, (r->y)*scale};
                                       CvPoint pt2 = {(r->x + r->width)*scale, (r->y + r->height)*scale};
    //env->SetObjectArrayElement(recPoints,i, pt1.x);
    return pFaceRectSeq->total;
    }

    Any Java array you can consider like one-dimensional array of arrays n-1 dimension. For example, you have a 3 dim. array of objects:
    Object[][][] arr = new Object[1][2][6]; It can be considered as a set of one-dimensional arrays:
    ==========================================
    |  dim   |           Type
    ==========================================
      0          1 element, an array of type �[[Ljava/lang/Object;�
      1          1 x 2 elements , an arrays of type �[Ljava/lang/Object;�
    So you can convert three-dimensional array to one-dimensional array like in C++:
    |�[Ljava/lang/Object;� | �[Ljava/lang/Object;� | �[Ljava/lang/Object;�
         6 objects                 6 objects                 6 objects

  • Question on System.arraycopy method and multidimensional array

    I'm trying to copy from single dimensional to multidimensional array using System.arraycopy method. The following is my problem.
    1) I need to specify the index of the multidimensional array while copying. Can I do that ? If yes , how???
    eg ; int a[] = new int[3];
    int b[] = new int[3][2]; I need to copy from a to b
    I tired the following and I'm getting an error.
    System.arraycopy(a,0,b[][1],0,3);
    How Can I achieve the above?? PLease Help --------------

    Java doesn't have multidimensional arrays. When you see an int[][] it's an array of arrays of ints. The arrays of ints might have different lengths like this one:int[][] arr =
    {{1,2,3,4},
    {1,2,3},
    {1,2},
    {1}
    };Do I need to say that arraycopy as you see it would fail in this case?
    If you know what kind of arrays you'll have you can simply implement your own arraycopy method (but it will not be as effecient as System.arraycopy) with a simple for-loop.

  • Synthesis bug with SV packed multidimensional array slices

    I've been using SV packed multidimensional arrays to do things like representing a bus which is many bytes wide, e.g. a 128-bit bus can be declared like this:
    logic [15:0] [7:0] myBus;
    You should be able to write "myBus[15:8]" to get the upper 64 bits (8 bytes) of this 128-bit wide packed value. However, I've found that in some expressions this produces some very buggy behavior. I've reduced it to a simplified example, with comments to show what works and what doesn't.
    `timescale 1ns / 1ps
    module sv_array_select (
    input logic sel,
    input logic [3:0] [1:0] i,
    output logic [3:0] outA,
    output logic [3:0] outB,
    output logic [3:0] outC
    // Works; equivalent to assign outA = {i[1], i[0]};
    assign outA = i[1:0];
    // Works; equivalent to assign outB = {i[3], i[2]};
    assign outB = i[3:2];
    // FAILURE
    // Synthesizes to equivalent of:
    // assign outC[2:1] = sel ? i[2] : i[0];
    // assign outC[3] = 1'bZ;
    // assign outC[0] = 1'bZ;
    assign outC = sel ? i[3:2] : i[1:0];
    endmodule
     I get this result in Vivado 2015.2 and 2013.2, haven't tried other tool versions.

    ,
    Yes, I can see that incorrect logic is getting generated by the tool.
    I will file a CR on this issue and will let you know the CR number.
    Thanks,
    Anusheel
    Search for documents/answer records related to your device and tool before posting query on forums.
    Search related forums and make sure your query is not repeated.
    Please mark the post as an answer "Accept as solution" in case it helps to resolve your query.
    Helpful answer -> Give Kudos
     

  • Multidimensional Array Sort

    Please help. I am very new to java and trying to build a multidimensional array. I have two variables 1)item_name and 2)item_value. These are values that I obtain by looping through a database result set. I need to build and array that can hold these variables. Once the multidimensional array is built I need to be able to sort it by item value.
    For example I would like to do something like this:
    while (rs.next)
    array.name = item_name
    array.value = item_value
    end
    array.sort(value)
    Thanks for any help!

    Don't use a multidimensional array. Use an array of objects, where the objects are of a class that you define. It might be something as simple as class Item that just has two fields--name and value--and their getters and setters. Or maybe just getters if you want the class to be immutable.
    Have the class implement Comparable and sort on value.
    If you sometimes want to sort on value and sometimes on name, then you'll need to either define two Comparators (one for name, one for value) or make the class Comparable on whichever is the more "natural" ordering and define a Comparator for the other one.
    Either put them in an array and use one of the java.util.Arrays.sort methods to sort them, or put them in a List (java.util.LinkedList or java.util.ArrayList) and use Collections.sort to sort them.

  • How to save joint's coordinates into multidimensional array

    Hello everyone, 
    i have a question that's seems silly but i'm stuck in it since yesterday !
    i'm developping a small application with ms kinect sdk 1.7 and when detecting skeleton and all joints are tracked i want to save it into multidimensional array of (20,3) which are respectively the number of joints in human body and the coordinates along
    the 3 axes. 
    my goal is to calculate after that the max and the min values throught the 3 axes.. so i began with this piece of code.
    private static double[][] JointTab = new double [20][3];
    double save_joints(Skeleton first)
    foreach (Joint j in first.Joints)
    for (int li = 0; li < 20; li++)
    JointTab[li][0] = j.Position.X;
    JointTab[li][1] = j.Position.Y;
    JointTab[li][2] = j.Position.Z;
    return JointTab;
    it indicates that the method does not return a value necessary ? how could i fix this error ? 
    i will need to call the JointTab after that how can i sort each colomn with Array.Sort() method  ?
    thanks for any help ! 
    DKF

    The issue you are having is not specific to the Kinect SDK. You will need to look into your managed code construction of the array since that is not valid. There are ways to create a single array of a structure which you can then provide your own enumeration.
    You may want to look at the generic collections of .Net to see what would be best since you will way to provide some logic to the sort since the points in space will need to calculate a length.
    Carmine Sirignano - MSFT

  • Multidimensional arrays

    I need help in creating a program that assigns a rock star name when they enter their own name. It must assign the same name to the same user's name, but different last names when that changes.

    Sorry?
    And what has it to do with multidimensional arrays?

  • CR XI: Multidimensional arrays?

    Post Author: dmcheng
    CA Forum: Formula
    Hi.  I don't suppose there's a way to do multidimensional arrays in CR XI?  I've checked the help and searched the forums with no luck, but hoping that someone might know of a workaround.ThanksDavid

    Post Author: Jagan
    CA Forum: Formula
    A workaround is to create asingle dimensional array with x*y elements. e.g.
    multi &#91;3&#93; &#91;6&#93;
    single &#91;3 * 6&#93;
    multi &#91;x&#93; &#91;y&#93; = single&#91;6*(x-1) + y&#93;

  • Multidimensional Arrays + Me + OOP = Fear

    node.java
    class node {
         int[][] grid = new int[0][0];
         void detect(){
              System.out.println(grid);
    game.java
    class game {
         public static void main(String args[]) {
              node a = new node();
              a.detect();
    The output of this code is:
    http://img237.imageshack.us/img237/6556/outputxy7.png
    I am trying to create an imaginary grid so I can implement A* algorithm into my game which will later be an applet.
    Why did the output of this come out so weird? I do not understand multidimensional arrays and I struggle to understand object oriented programming.
    I have known Java since Nov 2006, but I have always dodge some of this difficult stuff. I am totally self taught and I have been learning through the Internet and a very old Java 2 book. So please speak "dumb" to me.
    Thank you,
    Andrew.

    Oh, grow up. If you get insulted this easily, you'll be inconsolable when you have to get a real job. I'm so sick of these children who want help but also want their genius to remain unquestioned.
    Anyway my point wasn't that you altered the image, but rather that you were careless in what you presented as data. Some of the stuff on that image couldn't possibly have worked with the code you posted. (In particular "java node" would not have even run. It wouldn't produce any output at all other than an error message.)
    Part of debugging is gathering real, useful, accurate information. And if you want help debugging you have to share real, useful, and accurate information. If you gather output and then change your code, you should at the very least make this clear.

  • Working with MultiDimensional arrays

    Hi,
    Just wondering if anyone could help with a problem Im
    having with multi-dimensional arrays in Java:-
    I want to create a multi-dimensional array (e.g. 3 dimensions). I know this can be defined by code such as:-
    int[ ][ ][ ] my_array = new int[10][10][10];
    (would create a 10x10x10)
    My problem is that I want to address the array with indexes that aren't known at compile time, trying to do this causes an error:-
    e.g. my_array[0][0][0] = 1; is ok (i.e. the element at 0,0,0 is set to 1)
    but if the indexes 0,0,0 are replaced by the return value of some function,
    e.g.
    my_index1 = generateIndex(x, y, .... etc);
    my_index2 = generateIndex(a, b, ...etc);
    my_index3 = generateIndex(f,g, .. etc);
    (where generateIndex is some function that returns an integer)
    and the array element set with
    my_array[my_index1][my_index2][my_index3] = 3;
    This generates an error. I know that this problem can be overcome through the use of pointers in C++ but since Java doesn't use pointers, im a bit stuck!
    I have come across a method that overcomes this for a 1D array, using the setInt function of the Array class, e.g.
    Array.setInt(my_1Darray, 0, 1); (would set the first value of my_1Darray to 1);
    (i.e. Array.setInt(array_name, int index, int value);
    But I can't see how this works with multidimensional arrays.
    If anyone could shed any light on this problem, that would be great.
    Thanks,
    Peter

    public class NDArray {
            public static void main(String[] s) {
                    int[][][] _3D = new int[10][10][10];
                    for (int c = 0; c < 1000; c++)
                            _3D[rnd()][rnd()][rnd()]=rnd();
                    for (int i=0; i < 10; i++) {
                      for (int j=0; j < 10; j++) {
                        for (int k=0; k < 10; k++) {
                            System.out.print(_3D[i][j][k]);
                            System.out.print(" ");
                      System.out.println();
                    System.out.println();
            static int rnd() {return (int) (10*Math.random());}
    /* output (example):
    7 0 0 4 9 9 3 0 0 2
    0 1 8 9 6 0 0 0 0 0
    5 3 0 5 0 0 1 0 0 3
    5 6 0 5 0 0 3 0 0 0
    0 0 0 0 4 0 0 5 8 6
    0 9 0 9 0 1 0 2 0 0
    3 3 8 6 0 0 1 0 3 4
    9 6 7 0 0 0 3 6 6 3
    2 0 8 7 0 1 4 0 7 0
    8 0 4 4 3 0 0 5 4 0
    0 0 0 0 3 0 1 0 0 4
    9 0 8 9 1 0 9 0 9 0
    0 8 3 4 1 0 8 0 0 2
    3 0 0 7 3 3 0 5 0 0
    0 0 0 1 4 6 0 0 0 3
    3 5 8 5 8 0 8 2 0 4
    4 0 1 7 0 1 0 4 4 0
    6 0 5 0 0 4 0 8 1 0
    0 0 6 6 2 0 0 4 5 0
    0 6 7 0 4 0 7 5 0 0
    2 4 0 5 0 0 0 2 1 7
    0 6 0 9 0 0 6 1 2 0
    0 5 9 0 1 2 4 0 8 6
    0 0 8 0 0 3 3 8 0 0
    4 7 5 9 0 8 1 0 0 9
    2 0 0 3 0 0 8 3 0 7
    0 6 0 6 0 0 0 0 1 0
    0 9 9 8 4 2 0 0 7 2
    4 0 0 9 0 0 0 1 0 6
    7 0 6 5 2 3 7 8 0 2
    0 0 3 5 0 0 0 0 0 0
    3 0 0 0 0 2 0 0 6 0
    6 0 3 3 6 0 4 0 1 6
    0 0 7 2 0 8 0 0 0 0
    0 0 9 0 6 8 2 1 0 0
    9 0 4 1 3 9 3 2 7 7
    0 3 1 0 3 0 0 9 0 5
    0 0 0 0 6 0 4 8 0 5
    1 8 4 6 7 0 0 4 4 0
    0 4 8 0 0 0 6 0 4 0
    0 9 3 0 0 0 6 0 0 8
    6 8 2 9 6 0 0 7 9 0
    7 1 9 0 0 5 0 2 3 0
    0 0 0 0 9 9 0 7 0 9
    9 8 8 2 9 8 0 5 8 0
    2 3 0 4 0 4 1 0 6 9
    3 3 0 0 0 0 7 6 9 3
    6 2 2 1 0 5 8 3 0 6
    0 6 0 0 0 0 0 0 7 5
    0 6 0 0 0 3 3 0 2 0
    3 6 5 5 8 2 0 9 1 0
    8 0 7 0 9 0 9 0 2 0
    0 2 9 0 0 1 2 4 0 2
    3 1 0 2 0 0 0 0 0 0
    0 5 0 3 8 8 3 0 0 0
    9 0 9 0 5 1 0 9 5 0
    8 0 0 8 8 7 0 3 1 0
    4 0 0 0 1 8 0 9 0 5
    0 0 6 6 0 0 5 2 6 8
    0 4 0 9 0 0 2 0 0 3
    0 5 8 1 7 0 0 4 2 0
    6 5 0 0 2 0 6 8 8 7
    0 0 0 0 3 0 8 4 0 0
    2 3 3 0 0 7 6 8 0 4
    4 1 7 3 8 0 2 3 3 0
    1 5 0 0 4 1 3 7 3 1
    0 0 0 6 0 6 0 0 3 0
    3 7 0 4 5 9 5 5 0 8
    3 8 6 4 0 0 0 1 6 0
    0 0 2 0 2 9 0 0 0 5
    0 5 6 0 5 5 4 0 6 7
    0 2 2 0 9 7 4 2 9 0
    4 0 5 4 8 3 0 0 2 0
    0 0 9 3 3 0 8 8 7 0
    0 7 9 7 0 0 0 7 1 0
    2 0 0 0 5 8 2 0 0 5
    2 4 9 6 6 0 0 0 6 0
    0 6 6 7 0 2 0 0 5 2
    0 9 0 4 8 5 1 0 7 6
    0 0 7 0 4 0 3 8 0 9
    9 4 0 0 0 4 0 0 0 5
    2 0 4 7 7 5 4 0 9 0
    0 0 1 0 5 0 1 0 6 0
    0 6 0 9 0 9 0 4 7 0
    5 9 6 6 2 8 8 4 1 4
    9 7 3 2 7 6 0 2 3 0
    3 1 5 0 8 0 0 0 0 0
    9 0 0 3 0 8 7 0 4 0
    8 6 6 4 0 4 6 4 5 0
    0 0 0 0 0 4 4 0 0 9
    8 8 0 2 0 0 0 1 0 0
    6 2 1 1 9 0 5 1 0 0
    0 9 1 0 6 0 4 0 0 0
    9 4 0 3 0 1 0 7 6 0
    0 9 0 7 8 6 0 5 0 0
    0 8 8 9 0 5 7 0 0 0
    0 4 5 1 6 0 5 2 9 3
    6 0 0 0 0 0 0 9 1 0
    5 9 1 9 2 5 3 0 0 9
    2 9 5 1 7 0 0 0 9 0
    */Seems to work just fine. How is your code different from mine?

  • How to pass a multidimensional array to an Oracle procedure?

    How can I pass a multidimensional array to oracle array?
    Thanx in anticipation,

    Look in to passing user defined type back and forth to Oracle. Any type that oracle supports, you can constract on the java side and send it across. Look into the SQLData class.

Maybe you are looking for

  • Once I add my .swf to Dreamweaver, the buttons are not clickable, how can I fix this?

    Hello there, I'd just like to start out by saying that this is the first time I have posted on these forums, so if I have done anything wrong, I apologize! Anyway, about my question, just like the title says, once I import the .swf into Dreamweaver t

  • Qosmio F20 - Built-In HDD error

    My F29 took a hefty knock today around the HDD area on the forward right,while my kids were playing around. In hefty i mean that when it got knocked it unclipped the speaker panal near the sreen. For a while it continued to work but about 10 mins lat

  • Placing deep etched images into Illustrator

    I am having problems when placing a deep etched image file into Illustrator CS2 from Photoshop CS2. When I place the file into Illustrator, it is not recognising the working path on the file, and is just coming in with a transparent rectangular backg

  • SQL Developer viewing schemas on an MS SQL Server

    Hi, I've connected SQL Developer to our MS SQL server in the hope we can dump some of the data it contains onto our Oracle 10g box. Problem is in the left hand connections pane we can only see one database on the sql server box at a time. If we want

  • Cannot open adobe reader files.....because it was not a supported type file.......

    Cannot open adobe reader file............could not open because it was not a supported type file...........or damaged by email.... What support does it need????