Fill up an array?

Hey
i want to fill up an array with a deck of cards
i don't really know how to do it
here is some code that will clarify the situation
public class Game {
    public void Game() {
    public static void main(String[] args){
      Kaart[]  kaarten;
      kaarten = new Kaart[53];
      int teller=0;
public class Kaart {
    private String color;
    private String value;
    public void kaart(String kleur, String waarde){
    this.color=kleur;
    this.value=waarde;
    public void Kaart(){
    public void setColor(String kleur){
    this.color=kleur;
    public String getColor(){
    return color;
    public void setValue(String waarde){
    this.value=waarde;
    public String getValue(){
    return value;
public String toString(){
        return value + color;
}

Ok, there is some light at the end of the tunnel
the array is filled till the 13th card of hearts. but the rest is empty
any ideas
and
i know the method vulArray() can be way shorter
public class Game {
    private Card[] deck;
    public Game() {
        deck = new Card[53];
    public void vulArray() {
        for (int i = 0; i < 53; i++) {
            switch (i) {
                case 0:
                    for (int j = 0; j < 13; j++) {
                        deck[j] = new Card("hearts", "" + j);
                case 1:
                    for (int j = 0; j < 13; j++) {
                        int c = 14;
                        deck[c] = new Card("Club", "" + "" + j);
                        c++;
                case 2:
                    for (int j = 0; j < 13; j++) {
                        int c = 27;
                        deck[c] = new Card("Diamond", "" + j);
                        c++;
                case 3:
                    for (int j = 0; j < 13; j++) {
                        int c = 40;
                        deck[c] = new Card("spade", "" + j);
                        c++;
    public void showDeck() {
        for (int j = 0; j < deck.length; j++) {
            System.out.println(deck[j].toString());
    public static void main(String[] args) {
        Game spel1 = new Game();
        spel1.vulArray();
        spel1.showDeck();
          

Similar Messages

  • Filling an int array

    Hi would anyone know how to fill an int array of size 20 with all random number between 0-19 and have no duplicates in the finished array.

    Oh yeah i have code done but it doesnt want to work properly. ill show you.
    public int randomNum(int x, int y) {
                int a=Math.max(x, y);
                int b=Math.min(x, y);
                return (int)Math.floor(Math.random()*(a-b))+b;
          * Checks the index list to see if it contains the random number
          * @param num
          * @param arr
          * @return
         public boolean hasNum(int num, int[]arr){
              int n = num;
              for(int i=0; i<arr.length;i++){
                   if(arr[i] == n)
                        return true;
              return false;
          * Return an integer [] for use as index positions
          * @return
         public int[] indexList(){
              int[] list = new int[uArr.length];
              for(int i=0;i<list.length;i++){
              int r = randomNum(0,19);
               while(!hasNum(r,list)){
                        list[i] = r;
                        r = randomNum(0,19);
                   System.out.println(""+list);
              return list;

  • Fill and object array

    I have too many books and not enough understanding on this subject.
    I am trying to fill an object type array with values and am totally confused. In my application, I successfully create a constructor in one file and test the object with some values in another file. I have two objects for employee and would like to place the object values into an object array. There is plenty of information on int[] arrays, but little on object arrays.
    After I can do the array fill:
    I would like to provide object values with JOptionPane.
    Change the print display to show all array elements
    But one thing at a time.
    I was thinking that objects exist first, then are loaded or filled into an object array. I seem to misunderstand as I am not performing the array fill very well. Following a book example seems to confuse me only more.
    Thank you
    //emp.java
    import java.util.*;
    public class Emp {
       private int id;
       private String name;
       private double salary;
       public Emp(int ident, String nm, double sal) {
         id = ident;
         name = nm;
         salary = sal;
       // method raise salary by 5 percent
       double raise() { return salary * 1.05;} // ends raise method
       // setters and getters
       public String getName()              { return(name); }
       public double getSalary()            { return(salary); }
       public int getID()                   { return(id); }
       public void setName(String nm)       { name = nm; }
       public void setSalary(double sal)    { salary = sal; }
       public void setID(int ident)         { id = ident; }
    }The test file
    //EmpTest.java
    import javax.swing.JOptionPane;
    public class EmpTest {
       public static void main(String[] args_) {
                 // Create object based on EmployeeTest2 class
                 // to add employee data to the array called empArray
                 Emp emp1 = new Emp(1,"Smith",2000);
                 Emp emp2 = new Emp(2,"Jones",2500);
                 //test and confirm the objects emp1 and emp2
                     int i;
                     String n;
                     double s;
                     double newsal;
                     // get the salary after the 5 percent raise
                     i = emp1.getID();
                     n = emp1.getName();
                     s = emp1.getSalary();
                     newsal = emp1.raise();
                     System.out.println("object Employee 1 ID: " + i + " Name: " + n + " Old Salary: " + s + " New salary: " + newsal);
                     i = emp2.getID();
                     n = emp2.getName();
                     s = emp2.getSalary();
                     newsal = emp2.raise();
                     System.out.println("object Employee 2 ID: " + i + " Name: " + n + " Old Salary: " + s + " New salary: " + newsal);
         // get the number of employees with JOptionPane
         String employeeCountString = JOptionPane.showInputDialog(
             "Employee Database " +
             "\nEnter the number of employees: ");
         // convert into an integer empcount
         int employeeCount = Integer.parseInt(employeeCountString);
         // initialize the empArray.
         Employee2[] empArray = new Employee2[employeeCount];
         fill(empArray);
         printContents(empArray);
       } //end main method
       private static void fill(Object[] my_arr) {
           int i;
           for (i = 0; i < my_arr.length; i = i + 1) {
         // get the name from the keyboard
         String employeeName = JOptionPane.showInputDialog(
             "Enter the employee name: ");
             // do something here to set the array element to employeeName
         // get the salary
         String employeeSalaryString = JOptionPane.showInputDialog(
             "Enter the employee monthly salary: ");
         //convert into a double
         double employeeSalary = Double.parseDouble(employeeSalaryString);
            //do something here to set array for salary
              my_arr[i] = new Employee2(1,"S1",5); // temporary values here
           } //ends for loop
       } // ends method
       private static void printContents(Object[] the_arr) {
          int i;
          for (i = 0; i < the_arr.length; i = i + 1) {
            System.out.print("Element: " + i);
            //System.out.println(" has the value : " + the_arr);
    System.out.println(" has the value : " + i);
    } //ends for loop
    } // ends printContents method
    } // ends EmpTest class

    what's the matter ?
    Try this :
    import javax.swing.JOptionPane;
    public class EmpTest {
         public static void main(String[] args_) {
              // Create object based on EmployeeTest2 class
              // to add employee data to the array called empArray
              Emp emp1 = new Emp(1, "Smith", 2000);
              Emp emp2 = new Emp(2, "Jones", 2500);
              // test and confirm the objects emp1 and emp2
              int i;
              String n;
              double s;
              double newsal;
              // get the salary after the 5 percent raise
              i = emp1.getID();
              n = emp1.getName();
              s = emp1.getSalary();
              newsal = emp1.raise();
              System.out.println("object Employee 1 ID: " + i + " Name: " + n + " Old Salary: " + s + " New salary: "
                        + newsal);
              i = emp2.getID();
              n = emp2.getName();
              s = emp2.getSalary();
              newsal = emp2.raise();
              System.out.println("object Employee 2 ID: " + i + " Name: " + n + " Old Salary: " + s + " New salary: "
                        + newsal);
              // get the number of employees with JOptionPane
              String employeeCountString = JOptionPane.showInputDialog("Employee Database "
                        + "\nEnter the number of employees: ");
              // convert into an integer empcount
              int employeeCount = Integer.parseInt(employeeCountString);
              // initialize the empArray.
              Emp[] empArray = new Emp[employeeCount];
              fill(empArray);
              printContents(empArray);
         } // end main method
         private static void fill(Object[] my_arr) {
              int i;
              for (i = 0; i < my_arr.length; i = i + 1) {
                   // get the name from the keyboard
                   String employeeName = JOptionPane.showInputDialog("Enter the employee name: ");
                   // do something here to set the array element to employeeName
                   // get the salary
                   String employeeSalaryString = JOptionPane.showInputDialog("Enter the employee monthly salary: ");
                   // convert into a double
                   double employeeSalary = Double.parseDouble(employeeSalaryString);
                   // do something here to set array for salary
                   my_arr[i] = new Emp(1, employeeName, employeeSalary); // temporary values here
              } // ends for loop
         } // ends method
         private static void printContents(Object[] the_arr) {
              int i;
              for (i = 0; i < the_arr.length; i++) {
                   System.out.print("Element # "+i+" Name= "+ ((Emp)the_arr).getName());
                   System.out.print("Salary # "+i+" Salary = "+ ((Emp)the_arr[i]).getSalary());
              } // ends for loop
         } // ends printContents method
    } // ends EmpTest class

  • Filling empty java array in C method

    Hi everyone,
    I'm passing to a C method an empty byte array from the Java Side. I want the C method to fill the Java byte array and return it at the end of the method to the java side.
    in the Java side, I have my byte array :
    byte[] myArray = null;
    then I'm passing the array to the C method as
    myMethod(myArray)
    in the C method I'M trying to access the array as follow :
    myMethod(jbyteArray myArray)
    jbyte* tab = *env)->GetByteArrayElements(env, myArray, 0);
    I'm getting an error at runtime. Can somebody help me with that issue please ? Thanks
    Sebastien

    You are not passing a byte array, you are passing null.
    If you want to pass a byte array you first have to create it using the new operator:
    byte[] myArray = new byte[theSizeOfTheArray];
    myMethod(myArray);If you want the JNI code to create the array, that is fine also, but in that case the native method would probably have to return the array instead of void.

  • How to fill a javascript array by a jsp array when the jsp is run

    Hi all,
    The problem i am facing is -- i want to use an javascript array in a function. The records are being fetched by jsp.
    How to fill the vaules in a javascript array, which are retrieved by a jsp array
    Please suggest
    Thanking You

    You can use the code below:
    <input type="button" value="Click Me" onclick="javascript:disp('<%= getString(str) %>')">
    <%!
    public String getString(String str[]){
    String arrElements="";
    for(int i=0;i<str.length;i++) {
    arrElements+=str[i]+",";
    return arrElements.substring(0,arrElements.length()-1);
    %>
    function disp(str) {
    arr = str.split(",");
    alert ("There are "+arr.length+" elements in the array");
    Hope this helps.

  • Filling in quadrilaterals in a pixel array

    Short version: Does anyone know of an algorithm like fillPolygon, but that works with a pixel array? (and doesn't need more than v1.1) Thanks.
    Long version:
    Hi. Hope there's a math guru among you who can give me a clue...
    I'm doing an animated 3D applet but restricted to pre-plugin Java - nothing post about 1.1. I'm double buffering for speed, with an int array [screenwidth*screenheight] for the pixels.
    At the start of each frame I want to colour in the areas where some flat rectangles (walls) are as the 'camera' sees them - quadrilaterals whose corners could be anywhere on or off the screen.
    For each line of the quadrilateral I can figure out how to find the on-screen start and end points - stopping where either the line or the screen stops, but I can't think of a fast algorithm to get from those 8 numbers per wall to a correctly filled-in pixel array.
    Thanks for your help.

    As your quadrilaterals are transformed rectangles,
    they should also be convex.
    From one vertex, with the most extreem ordiante in a
    chosen direction (eg the left-most) iterate in one
    direction (eg +ve x) along the two edges to the
    adjacent vertices using Bresenham's algorithm. That
    will give you two points with a common ordinate (eg
    (x, y0(x)) and (x, y1(x))), between which you may
    fill a line.
    On encountering another vertex, continue iterating
    along the next edge until the next vertex. When the
    furthest vertex is reached, you have filled your
    convex quadrilateral.
    Petethis approach is just fine and about as fast as you can get.
    another approach is filling the qualiteral (works as well for any convex
    polygon) by means of a triangle fan ...
    so for quadliteral with vertices A, B, C, D (each having x and y copmonents) you draw a triangle fan around a pivot point (lets say that is vertex A) like this
    drawTri (A, B, C)
    drawTri (A, C, D)
    or for a 5 vertex polygon (A, B, C, D, E)it would be
    drawTri (A, B, C)
    drawTri (A, C, D)
    drawTri (A, D, E)
    this works just as well, with a few minor advantages and disadvantages ...

  • Fill array with file names

    What am I missing?  I've got alerts that should pop up if it works and if it fails but instead it does nothing, I'm sure its possible to create an array that is made up of all the file names of a folder.  In the past I've had to enter all the values one a time and some of these folders have 200+ files in it.
    #target illustrator
    filltotesTempArr
    function filltotesTempArr()
    var toteTemparray = new Array(toteTemps)
    var toteTempPath = Folder ("S:/Illustrator JS Palette/Direct Template Calls/Totes");
    var allFiles = artPath.getFiles(order);
    var toteTemps
    if (allFiles.length > 0)
        for (i=0;i<allFiles.length;i++)
                toteTemps = toteTemps + app.open(allFiles[i] )
              }//end for
          alert("Your array has the current values:" + toteTemps);
        }//end if
        else
        alert("Script to fill Totes Templates Array has failed");

    I need to take all the files inside of a folder, and put their file names in an array like this;
    var totesarr1= new Array ("A165331","A165332","A165333","A165334","A165337","A165338","A165344","A165348", "A165349",
    "A165352","A165353","A203","A210","A211","A214","A222","A229","A231","A232","A234","A248","A250","A252","A268",
    "A271","A272","A278","A290","A292","A322","A323","A324","A325","A327","A330","A402","A404","A405","A407","A408",
    "A409","A410","A411","A414","A415","A417","A420","A422","A423","A424","A425","A427","A430","A436","A438","A439",
    "A440","A441","A443","A446","A448","A449","A450","A451","A452","A454","A455","A456","A460","A461","A468","A470",
    "A490","A495","A497","A500","A508","A509","A510","A512","A513","A514","A518","A524","A525","A526","A527","A530",
    "A533","A534","A536","A543","A581","A582","A587","A602","A619","A624","A705","A707","A710","A714","A715","A739",
    "A740","A741","A742","A743","A744","A745","A748","A750","A751","A752","A753","A754","A755","A756","A763","A800",
    "A801","A804","A806","A811","A815","A817","A818","A819","A824","A832","A835","A836","A838","A841","A844","A848",
    "A849","A852","A854","A856","A857","A859","A861","A863","A865","A866","A868","A871","A873","A877","A879","A881",
    "A885","A888","A890","A894","A899","A900","A902","A904","A940","A941","A943","A944","A945","A948","A97307","A97309",
    "A97313","A97314","A97315","A97316","A97321","A97326","A97340","A97342","A97708","A97715","F742","F751","V6432");
    so the closest thing that I can come up with is this;
    #target illustrator
    filltotesTempArr
    function filltotesTempArr()
    var toteTemparray = new Array(toteTemps)
    var order = new RegExp(input);
    var toteTempPath = Folder ("S:/Illustrator JS Palette/Direct Template Calls/Totes");
    var totetempnames = toteTempPath.getFiles();
    var totetemps = new Array ()
    var allFiles = toteTempPath.getFiles();
    if (allFiles.length > 0)
        for (i=0;i<allFiles.length;i++)
                toteTemps = toteTemps + "," + app.open(allFiles[i])
              }//end for
          alert("Your array has the current values:" + toteTemps);
        }//end if
        else
        alert("Script to fill Totes Templates Array has failed");
    alert ("Script is Done")
    but even this dosn't work like it should
    #target Illustrator
    GetTempNames;
    function GetTempNames ()
    var toteTempPath = Folder ("S:/Illustrator JS Palette/Direct Template Calls/Totes");
    var toteTempNames = toteTempPath.getFiles()
    var totetemparr = new Array ( toteTempNames )
    alert ("script is done get ready");
        alert ("Here " + totetemparr);
    so now I'm at a loss

  • Error on a simple function to fill an array plz hlp

    Hi guys.
    I'm trying to fill in an array with a simple function, here is the code
    public class rekener {
        int getal;
        int counter=-1;
        int[] getallen= new int[5];
        StringBuffer buffer= new StringBuffer();
        public void getGetal(int getal){
            this.getal= getal;
            counter++;
            getallen[counter]= getal;
        public String getArray(){
           for(int i: getallen){
               buffer.append(i);
           return buffer.toString();
    }i'm calling this function from a console application in this way....
    import java.util.Scanner;
    class venster{
       public static void main(String args[]){
           int getal;
           rekener rekener= new rekener();
           Scanner input= new Scanner(System.in);
           System.out.println("Voeg toe een nummer A.U.B");
           getal= input.nextInt();
           rekener.getGetal(getal);
           System.out.println("voeg nog een nummer toe");
           getal= input.nextInt();
           rekener.getGetal(getal);
           System.out.println("voeg nog een nummer toe");
           getal= input.nextInt();
           rekener.getGetal(getal);
           System.out.println("voeg nog een nummer toe");
           getal= input.nextInt();
           rekener.getGetal(getal);
           System.out.println("voeg nog een nummer toe");
           getal= input.nextInt();
           rekener.getGetal(getal);
           System.out.println("voeg nog een nummer toe");
           getal= input.nextInt();
           rekener.getGetal(getal);
           String list= rekener.getArray();
           System.out.println(""+list);
    }the problem is that the last function "getGetal();" which should deliver the StrinBuffer in a string format, does not do so, but gives me this error
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
            at rekener.getGetal(rekener.java:22)
            at venster.main(venster.java:37)
    Java Result: 1the line 22 is this :
    getallen[counter]= getal;this makes me think that the function that should fill the array isn't really doing it,
    Even if i change the volume of the array to 4 or 6 "even though 5 is the correct ammount since i'm inserting 6 integers", keeps on giving me the same error
    Do you now any other solution in order to fill in an array from an external function?
    Thank you and have a nice day
    Edited by: classboy on Dec 12, 2009 11:01 PM

    classboy wrote:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
    at rekener.getGetal(rekener.java:22)
    at venster.main(venster.java:37)The error message is telling you exactly what's wrong. On linke 22 of rekener.java (should be Rekener--class names conventionally start with uppercase), you are trying to access the 6th element, at index 5, of an array that has at more 5 elements, at indices 0..4
    the line 22 is this :
    getallen[counter]= getal;
    So counter is 5. But getallen has only 5 elements at indices 0..4, or fewer.
    this makes me think that the function that should fill the array isn't really doing it, It has nothing to do with whether the array is being "filled." Rather, it's just that the size of the array is less than what you're trying to access.
    Even if i change the volume of the array to 4 or 6 "even though 5 is the correct ammount since i'm inserting 6 integers", keeps on giving me the same errorNo idea what you're saying here, but the compiler doesn't lie. You're trying to access an array element that doesn't exist.
    Put print statements in your code so you can see what's happening at each step of the way, and figure out what you did to tell it to access elements that don't exist.

  • ¿How to fill an array with random letters?

    Hello, I was wondering If filling a bidimensional array
    (8x10 for example) with random letters could be done in C#, I've tried tons of stuff, but I can't manage to do it. Thanks in advance.

    I was wondering If filling a bidimensional array
    (8x10 for example) with random letters could be done in C#, I've tried tons of stuff, but I can't manage to do it.
    >I was wondering If filling a bidimensional array (8x10 for example) with random letters
    >could be done in C#,
    Yes.
    >I've tried tons of stuff, but I can't manage to do it.
    With exactly which part of this assignment are you having trouble?
    Can you create a 2-dim array of characters?
    Can you generate a random letter?
    Show the code you have written so far.
    Don't expect others to write a complete solution for you.
    Don't expect others to guess as to which part you're having difficulty with.
    Show the code you have working, and the code which you have tried which isn't working,
    Explain what is happening with it which shouldn't.
     - Wayne

  • Performance of System.arraycopy and Arrays.fill

    I have some code where I call a function about 1,000,000 times. That function has to allocate a small array (around 15 elements). It would be much cheaper if the client could just allocate the array one single time outside of the function.
    Unfortunately, the function requires the array to have all of its elements set to null. With C++, I would be able to memset the contents of the array to null. In Java, the only methods I have available to me are System.arraycopy() and Arrays.fill().
    Apparently, Arrays.fill() is just a brain-dead loop. It costs more for Arrays.fill() to set the elements to null than it does to allocate a new array. (I'm ignoring possible garbage collection overhead).
    System.arraycopy is a native call (that apparently uses memcpy). Even with the JNI overhead, System.arraycopy runs faster than Arrays.fill(). Unfortunately, it's still slower to call System.arraycopy() than it is to just allocate a new array.
    So, the crux of the problem is that the heap allocations are too slow, and the existing means for bulk setting the elements of an array are even slower. Why doesn't the virtual machine have explicit support for both System.arraycopy() and Arrays.fill() so that they are performed with ultra-efficient memsets and memcpys and sans the method call and JNI overhead? I.E. something along the lines of two new JVM instructions - aarraycpy/aarrayset (and all of their primitive brethern).
    God bless,
    -Toby Reyelts

    A newly allocated array begins its life with null in its elements. There is no need to fill it with null.
    As Michael already stated, I'm not redundantly resetting all of the elements to null. Here's some code that demonstrates my point. You'll have to replace my PerfTimer with your own high performance timer. (i.e. sun.misc.Perf or whatever) Also note that the reason I'm only allocating half the array size in allocTest is to more accurately model my problem. The size of the array I need to allocate is variable. If I allocate the array outside of the function, I'll have to allocate it at a maximum. If I allocate inside the function, I can allocate it at exactly the right size.import java.util.*;
    public class AllocTest {
      private static final int count = 100000;
      public static void main( String[] args ) {
        for ( int i = 0; i < 10; ++i ) {
          allocTest();
        double allocStartTime = PerfTimer.time();
        allocTest();
        double allocTime = PerfTimer.time() - allocStartTime;
        for ( int i = 0; i < 10; ++i ) {
          copyTest();
        double copyStartTime = PerfTimer.time();
        copyTest();
        double copyTime = PerfTimer.time() - copyStartTime;
        for ( int i = 0; i < 10; ++i ) {
          fillTest();
        double fillStartTime = PerfTimer.time();
        fillTest();
        double fillTime = PerfTimer.time() - fillStartTime;
        System.out.println( "AllocTime (ms): " + allocTime / PerfTimer.freq() * 1000 );
        System.out.println( "CopyTime (ms): " + copyTime / PerfTimer.freq() * 1000 );
        System.out.println( "FillTime (ms): " + fillTime / PerfTimer.freq() * 1000 );
      private static void allocTest() {
        for ( int i = 0; i < count; ++i ) {
          Object[] objects = new Object[ 8 ];
      private static void copyTest() {
        Object[] objects = new Object[ 15 ];
        Object[] emptyArray = new Object[ 15 ];
        for ( int i = 0; i < count; ++i ) {
          System.arraycopy( emptyArray, 0, objects, 0, emptyArray.length );
      private static void fillTest() {
        Object[] objects = new Object[ 15 ];
        for ( int i = 0; i < count; ++i ) {
          Arrays.fill( objects, null );
    }I getH:\>java -cp . AllocTest
    AllocTime (ms): 9.749283777686829
    CopyTime (ms): 13.276827082771694
    FillTime (ms): 16.581995756443906So, to restate my point, all of these times are too slow just to perform a reset of all of the elements of an array. Since AllocTime actually represents dynamic heap allocation its number is good for what it does, but it's far too slow for simply resetting the elements of the array.
    CopyTime is far too slow for what it does. It should be much faster, because it should essentially resolve to an inline memmove. The reason it is so slow is because there is a lot of call overhead to get to the function that does the actual copy, and that function ends up not being an optimized memmove. Even so, one on one, System.arraycopy() still beats heap allocation. (Not reflected directly in the times above, but if you rerun the test with equal array sizes, CopyTime will be lower than AllocTime).
    FillTime is unbelievably slow, because it is a simple Java loop. FillTime should be the fastest, because it is the simplest operation and should resolve to an inline memset. Fills should run in single-digit nanosecond times.
    God bless,
    -Toby Reyelts

  • Creating 2D Array with info from file and Saving it to a text file

    what im trying to do is take my nice little data structure and put it into a 2D array which i can copy and paste as code into my compiler... it takes TDPoints(like Point2D except has z value) which are in Faces(an arraylist of points, each face also has a color value), which are in objects(arraylist of faces, + other attributes)
    for my sake im only working with one object, here is my code:
         private void saveArrayToTXT(String name) throws IOException
              double X;
              double Y;
              double Z;
              FileOutputStream xos = new FileOutputStream("C:/Program Files/Xinox Software/JCreatorV3LE/MyProjects/ThreeDRemake/Files/" + name + ".txt");
              DataOutputStream fos = new DataOutputStream(xos);//ObjectOutputStream oos = new ObjectOutputStream(fos);
              //oos.writeObject(myObject);
              //for(int ob = 0; ob < ((ArrayList)myObject).size(); ob++)
                        ThreeDObject object = (ThreeDObject)(((ArrayList)myObject).get(0));
                        fos.writeChars("{");
                        for(int shape = 0; shape < object.getFaces().size(); shape++)
                             fos.writeChars("{");
                             ArrayList faces = object.getFaces();
                             for(int count = 0; count < ((Face)(faces.get(shape))).getPoints().size(); count++)
                                  X = ((TDPoint)(((Face)(faces.get(shape))).getPoints().get(count))).getX();
                                  Y = ((TDPoint)(((Face)(faces.get(shape))).getPoints().get(count))).getY();
                                 Z = ((TDPoint)(((Face)(faces.get(shape))).getPoints().get(count))).getZ();
                                   fos.writeChars("" + (int)X);
                                   fos.writeChars(",");
                                   fos.writeChars("" + (int)Y);
                                   fos.writeChars(",");
                                   fos.writeChars("" + (int)Z);
                                   if(count != ((Face)(faces.get(shape))).getPoints().size()-1)
                                   fos.writeChars(",");
                                   if((count == ((Face)(faces.get(shape))).getPoints().size()-1) && (count < 5))
                                        for(int lkj = count; lkj <5; lkj ++)
                                             fos.writeChars(",");
                                             fos.writeChars("" + (int)X);
                                             fos.writeChars(",");
                                             fos.writeChars("" + (int)Y);
                                             fos.writeChars(",");
                                             fos.writeChars("" + (int)Z);
                              fos.writeChars("}");
                         fos.writeChars("}");
              fos.close();
              xos.close();
         } i happen to know for a fact that there are no faces with more than 6 points, so i used this line:if((count == ((Face)(faces.get(shape))).getPoints().size()-1) && (count < 5))and everything that follows to write ditto information(the last point) over and over again to fill up the array(i could even write a null value here if i wanted)
    the problem im having is i seem to be missing two right brackets("}") and with all the information thats going through these loops its impossible to trace where and what is going wrong. can anyone point out any possible flaws to help me figure out what im doing wrong??
    Message was edited by:
    sosleepy
    also, though its not important, when i do:fos.writeChars("...")//(i used writeChars(); to save myself the hassle of typeing writeChar((int)'char').)it writes a blankspace(spacebar) between each string i write, how can i prevent this from happening?
    Message was edited by:
    sosleepy
    nvm i just realized what i was doing wrong... fixed the error, but a reply on the spaces between writes would be nice

    You asked this same question a couple of months ago: http://forums.ni.com/t5/LabVIEW/Reading-Data-From-text-File/m-p/1756390#M612805
    Well, you can use the Read Text file to read the file, and then just extract the lines... Ben64 showed you a method to use regular expressions. That's one way.
    For Excel you can use the Report Generation Toolkit, or you can code it yourself using ActiveX. There's an example that ships with LabVIEW on writing a table to Excel.
    For database operations you can use the Database Toolkit, or you can try to use LabSQL.

  • Periodically updating a graph from a continually updating array

    I'm back after a few weeks of playing around with LabVIEW to try to fix it myself. I've gotten pretty far, I think, considering I have only myself and the two books "Learning with LabVIEW 7 Express" and "LabVIEW Graphical Programming" to help me!
    My previous post on this subject can be found here, though it is not necessary to read in order to help me with my current problem.
    With this post you will find 3 VI's that I have created, these are:
    "sub-test.vi" is my first attempt at creating a usefull sub-vi. I have documented it and made an icon for it, but all it does is really save me from a few extra blocks in my program.
    "neat but not working.vi" or ex1: I think it looks neat, but it will not work the way I would expect it too.
    "messy and still not working.vi" or ex2: this one looks more messy, uses a for loop instead of a while loop and is not working the way I want it too either.
    What I am trying to do:
    I have incomming serial data tagged with the channel name. I know how to extract the data (16bit unsigned int) from the header and footer using match patterns and type-cast (see sub-test.vi). I now want to "save" the incomming channel data (for simplicity lets assume that I only have one channel, called T1) in an array called T1. Naturally, I need to be relativly sure that my array actually does store my data (coming in at about 2/second). I then want to display that array in a graph at a set interval, say, every 2 seconds for example.
    So far I have been playing around like a blind person on an open field, feeling my way in the dark. I have tried a lot of solutions that seemed like good and logical solutions to me, but they didn't work, so obviously my logic is flawed.
    In Ex1 I tried to time the graphing by placing the graph and array in a sepparate while loop along with a "Wait until next ms multiple". The reading of the serial port is handled in a separate while loop running at max speed to catch all incomming data. It doesn't work the way I want it too.
    In Ex2 I tried to achieve my goal with another tactic. In this I get the graph to display stuff all the time, but I am unable to time the "refresh" of the graph.
    You may notice that I use the "old" serial port VI's (if you take context help on the Serial Port Init VI you will see a note explaining how it has been replaced with VISA VI's in the functions palette.. I have tried to use those, but I find them to be more difficult to set up. That is, I got it up and running and accepting data, but I got some errors and crashes from time to time, so I guess I used them incorrectly. Anyway, what I want to say is that if you feel that I should use the VISA VI's instead, I will need someone to set them up correctly for me the first time so I can see how it should be done.
    Both Greg McKaskle and Brian Powell provided a lot of help in my first thread at the very beginning of my project, and I hope that someone will be just as helpfull this time around!
    I use LabView 7 (the posted VI's from school) and Labview 7 Express on my personal laptop. (what -is- the functional difference between the two? I have not found anything? The only difference beeing that the Express have a watermark on the VI's?
    All the systems use Windows XP
    Attachments:
    Sub-test.vi ‏16 KB
    neat_but_not_working.vi ‏34 KB
    messy_and_still_not_working.vi ‏46 KB

    aha! I thougth that when I used the "counter" to see how many bytes waited for me at the port, then it wouldn't put lots of 0's in my array.
    I guess I could save the incomming stream to a file (that is a requirement, I need to log the data to a file) and then read the port every n'th second so that I know it contains roughly x samples and then parse and display all of that data. If I manually allocate the port-buffer size to hold the expected number of bytes + a marginal, that could work, right? In which case I should use a case structure (if "graph on" is true, then, say, every second, read the port buffer, parse the data into their respective arrays and graph/chart them).
    I don't need to display all the received data, but if I use a chart I don't have to worry about the buffers since my total data ammount (per. chart) will be less than 45000.
    I will look into charts again, I just tested to pass arrays to a chart, and that works too, with the added benefit that I can, as you say, have a display buffer so that I don't have to worry about that with my arrays. I can pass fixed size arrays to the chart and the chart will keep a (limited) history for me. I think that will work out great. The total number of data points at the end of the 6 hours should be around 43200, menaning I can hold the entire 6 hours in the chart buffer too without it impacting the performance to much.
    So what I need to fix now, regardless, is the "read from port" function so that it does not fill up my array with zeros!
    And I noticed in a test VI that generates 3 constant value arrays and one "random number 0 to 1" array, that if I pass it all to the chart, the data is not displayed as expected. In the included VI, the graph shows 3 straight lines and the random number, while the chart doesnt. In the chart there are no stright lines. Also, the top one in the chart (I have 4 on display, and I run them stacked) has all the lines, while in the other 3 I get one line (channel) just as I wanted. Why is that? I'll look into all the problems myself, but if someone could give a tip that would be great because I am still very much a student and learning by trial and error can be very frustrating.
    Attachments:
    array_and_graph_conondrum.vi ‏48 KB

  • Passing Array to Another Method

    Hello, I created a program with an array in one of the methods. I have been trying to figure out how to correctly pass the array to another method in the same class. I know my problem is in my method delcaration statements. Could someone please show me what I am doing wrong? Please let me know if you have any questions. Thanks for your help.
    import javax.swing.*;
    import java.util.*;
    class Bank1 {
         public static void main(String[] args) {
              Bank1 bank = new Bank1();
              bank.menu();
         //Main Menu that initializes other methods
         public void menu( ) {
              Scanner scanner = new Scanner(System.in);
              System.out.println("Welcome to the bank.  Please choose from the following options:");
              System.out.println("O - Open new account");
              System.out.println("T - Perform transaction on an account");
              System.out.println("Q - Quit program");
              String initial = scanner.next();
              char uInitial = initial.toUpperCase().charAt(0);
              while (uInitial != 'O' && uInitial != 'T' && uInitial != 'Q') {
                   System.out.println("That was an invalid input. Please try again.");
                   System.out.println();
                   initial = scanner.next();
                   uInitial = initial.toUpperCase().charAt(0);
              if (uInitial == 'O') newAccount();
              if (uInitial == 'T') transaction();
         //Method that creates new bank account
         public Person[] newAccount( ) {
              Person[] userData = new Person[1];
              for (int i = 0; i < userData.length; i++) {
                   Scanner scanner1 = new Scanner(System.in);
                   System.out.println("Enter your first and last name:");
                   String name = scanner1.next();
                   Scanner scanner2 = new Scanner(System.in);
                   System.out.println("Enter your address:");
                   String address = scanner2.next();
                   Scanner scanner3 = new Scanner(System.in);
                   System.out.println("Enter your telephone number:");
                   int telephone = scanner3.nextInt();
                   Scanner scanner4 = new Scanner(System.in);
                   System.out.println("Enter an initial balance:");
                   int balance = scanner4.nextInt();
                   int account = i + 578;
                   userData[i] = new Person( );
                   userData.setName               ( name );
                   userData[i].setAddress          ( address );
                   userData[i].setTelephone     ( telephone );
                   userData[i].setBalance          ( balance     );
                   userData[i].setAccount          ( account     );
                   System.out.println();
                   System.out.println("Your bank account number is: " + userData[i].getAccount());
              return userData;
              menu();
         //Method that gives transaction options
         public void transaction(Person userData[] ) {
              System.out.println(userData[0].getBalance());

    Thank you jverd, I was able to get that to work for me.
    I have another basic question about arrarys now. In all of the arrary examples I have seen, the array is populated all at once using a for statement like in my program.
    userData = new Person[50];
    for (int i = 0; i < userData.length; i++) In my program though, I want it to only fill the first array parameter and then go up to the main menu. If the user chooses to add another account, the next spot in the array will be used. Can someone point me in the right direction for doing this?

  • Trying to Clone an array object that contains other objects

    I have an employee object with the fields name (String), Salary (Double), and hireDay (Date). Since the date field contains many int fields (year, month etc..), using a straight clone will not work.
    What I want to do is copy an array of employees into a new array.
    For example:
    Employee [] newEmps = (Employee[])OldEmps.clone()
    In the employee class, I implement the Cloneable interface and my code so far will copy one Employee. How do I change this to copy an array of empoyees? Specifically, since hireDay contains many fields, a straight super.clone of the array won't work. Here is my clone code:
         public Object clone()
         try {
              // call Object.clone()
         Employee cloned = (Employee)super.clone();
              // clone mutable fields
    cloned.hireDay = (Date)hireDay.clone();
         return cloned;
         catch (CloneNotSupportedException e)
         { return null; }
    Any help is appreciated. Thanks!
    -Eric

    There's so much I don't understand about that, it just
    isn't worth asking. Let me spell out my previous post
    since it seems to have gone right over your
    head.Employee[] emps;
    // here you fill in the array of Employees
    Employee[] clonedEmps = new Employee[emps.length];
    for (int z=0; z<emps.length; z++) {I understand this next line of code. My question lies within the clone() function
    clonedEmps[z] = emps[z].clone();OK - Let me try to clear things up. If we take from your example the original array "emps". Now for me, emps, is already filled up in main().
    So in main() when I call emps.clone(), my clone function starts running:
    // the employee class (which I created) implements the Cloneable
    // interface
    // This clone function is inside my employee class
    public Object [] clone()
    try {
    Employee [] cloned = (Employee)super.clone();
    // IS THIS NEXT LINE OF CODE REQUIRED TO MAKE A DEEP COPY? IF SO, How would I implement perhaps a for loop that would copy the hireDay from each element in the original array to the elements in the the new array?
    // Obviously, each employee (element in the array) has a hireDay
    // Please modify this next line of code to show me how.
    cloned.hireDay = (Date)hireDay.clone();
    return cloned;
    catch (CloneNotSupportedException e)
    { return null; }
    If I wanted to access say the "hireDay" field of the 3rd element in the original employee array INSIDE THE CLONE FUNCTION - then how would i access it?
    Thanks
    -Eric

  • Array required, passing as an arguement to contructor which wants an array

    Hello again, can you help me with this?
    here is the error
    C:\jDevl\GameTest.java:19: array required, but Lot649.Ticket1 found
              lotto[0] = new Ticket1(1,2,12,1982, 3, 11, 12, 14, 41, 43, 13);
    ^
    C:\jDevl\GameTest.java:20: array required, but Lot649.Ticket1 found
              lotto[1] = new Ticket1(2,2,19,1982, 8, 33, 36, 37, 39, 41, 9);
    ^
    C:\jDevl\GameTest.java:21: array required, but Lot649.Ticket1 found
              lotto[2] = new Ticket1(3,2,26,1982, 1, 6, 23, 24, 27, 39, 34);
    ^
    HERE IS THE GAMETEST CODE, I BELIEVE THE PROBLEM IS WITH MY CONSTRUCTOR
    IN THE TICKET CLASS...
    public class GameTest{
         public static void main( String args[]){
              String result = "";
              //fill the lottery array with 5 ticket objects
              Ticket1 lotto = new Ticket1();
              Ticket1 t = new Ticket1();
                                  //recNo,mmddyr, n1, n2, n3, n4, n5, n6, n7}
              lotto[0] = new Ticket1(1,2,12,1982, 3, 11, 12, 14, 41, 43, 13);
              lotto[1] = new Ticket1(2,2,19,1982, 8, 33, 36, 37, 39, 41, 9);
              lotto[2] = new Ticket1(3,2,26,1982, 1, 6, 23, 24, 27, 39, 34);
              lotto[3] = new Ticket1(4,3,3,1982, 3, 9, 10, 13, 20, 43, 34);
              lotto[4] = new Ticket1(5,3,3,1982, 3, 11, 12, 14, 41, 43, 14);HERE IS THE TICKET CLASS CODE... dang those arrays, i believe i have messed up somehow with the arrays passing as args.
    public class Ticket1{
         private int recNum;
         private int mm;
         private int dd;
         private int yy;
         private int nArray[] = new int[7];
         public Ticket1(){
                        recNum = 0;
                        //drawDate = dDay.getDate();
                        //Date dD = new Date();
                        //drawDate = dDay.getDate();
                        mm = 1;
                        dd = 1;
                        yy = 1900;
                        nArray[0] = 0;
                        nArray[1] = 0;
                        nArray[2] = 0;
                        nArray[3] = 0;
                        nArray[4] = 0;
                        nArray[5] = 0;
                        nArray[6] = 0;
         }//end of constructor
         public Ticket1( int rec, int mon, int day, int year, int n1, int n2,
                         int n3, int n4, int n5, int n6, int n7){
              recNum = rec;
              //drawDate = dDay.getDate();
              //Date dD = new Date();
              //drawDate = dDay.getDate();
              mm = mon;
              dd = day;
              yy = year;
              nArray[0] = checkNum(n1);
              nArray[1] = checkNum(n2);
              nArray[2] = checkNum(n3);
              nArray[3] = checkNum(n4);
              nArray[4] = checkNum(n5);
              nArray[5] = checkNum(n6);
              nArray[6] = checkNum(n7);
         }//end of ticket constructor
         public Ticket1( int recA, int monA, int dayA, int yearA, int arrayName[] ){
              recNum = recA;
              mm = monA;
              dd = dayA;
              yy = yearA;
              nArray[0] = arrayName[0];
              nArray[1] = arrayName[1];
              nArray[2] = arrayName[2];
              nArray[3] = arrayName[3];
              nArray[4] = arrayName[4];
              nArray[5] = arrayName[5];
              nArray[6] = arrayName[6];
         }//end of Ticket1 constructor

    Ticket1 lotto = new Ticket1();lotto is not delcare as an array and you wants it to act like an array?
    lotto[0] = new Ticket1(1,2,12,1982, 3, 11, 12, 14, 41, 43, 13);
    lotto[1] = new Ticket1(2,2,19,1982, 8, 33, 36, 37, 39, 41, 9);you should do :
    Ticket1 lotto[] = new Ticket1[5];

Maybe you are looking for

  • Blue screen after shut down, service station won't work on reboot

    A blue screen suddenly appeared on shut down yesterday, and my laptop immediately restarted after. On restart, a message popped up saying that Toshiba Service Station stopped working. Last time I shut down my laptop the blue screen doesn't appear any

  • Standby rebuilding

    Hello! I have previously created a standby environment with one primary and one standby with oracle 11g and realtime apply. After some times we noticed that archives were not being aplpied on standby even though they were shipped, so we decided to re

  • Is lightroom a stand alone program

    I'm working on a slightly outdated laptop...and I desperately need access to Adobe photo editing capabilities. I could not install a free trial of Ps and Lightroom...wondering if Lightroom alone will work?

  • Possibly Nuked 8900

    I need serious help here with this BB. I recieved this BB as a hand over from my older sister who bought a 9700. It worked marvulously for the first few weeks then suddenly it got discharged.  I came home and charged it for hours to just find out tha

  • User's List

    Hello, What is the T-CODE or Progrm to see how many BI users login in a perticular day? Thanks