Hopefully an easy question about arrays

hi there
is there any way of creating an array of objects that is of unspecified size at the time of creating and then add objects as and when they are read from a file?
longer explanation:
i am creating molecule visualization software. the molecule's structure is stored in a text file, ie each line has info on one atom ie 3d coords etc. i'm storing the molecule structure in an object (Molecule.java) which has an array (Structure[]) of atoms (Atom.java). obviously molecules can have any number of atoms in it and you don't know how many until you've gone through the whole file and counted. The only way i can think of doing it is to go through the whole file, coun the atoms, close the file, create the Molecule object with the structure array size of NoOfAtoms and then open the file again and add the atoms as i go through them again. however, i refuse to believe this is the most efficient way of doing it as i have to go throguh the same file twice which brings me back to my original question.
as i said i'm hopeing there is a simple answer
cheers

Use a Collection . Use a Vector, ArrayList or even a Hashtable. You do not need to define the size of these objects and can add and remove Objects from them whenever you want

Similar Messages

  • Question about arrays

    I have a question regarding arrays. I have a contact class and two classes that extend from it a SchoolContact class and FamilyContact class. Right now as my code is I have three diffrernt arrays to hold all the info. Is there a way to store all this info into one array and print out only the School contacts at one time if the user enters that option or print out all the options at one time if the user selects that? my code is below
    //The imports below are for I/O
    import java.util.*;
    import java.io.*;
    // Declare a public class
    public class CodeExample {
         public static void main(String[] args) {
              // Create scanner
              Scanner sc = new Scanner(System.in);
              //Declare array to hold school contact
              SchoolContact[] schoolContactInfo = new SchoolContact[10];
              FamilyContact[] familyContactInfo = new FamilyContact[10];
              Contact [] contactInfo = new Contact [10];
              // Declare variables
              int menuOption, creditHours, area, prefix, suffix, studentId, studentContactsSoFar = 0, familyContactsSoFar = 0, contactsSoFar = 0;
              double gpa;
              char studentData, familyRelationOption;
              String menuOption2, menuOption3;
              // Get menu to display
              do {
                   System.out.println("-----MENU-----");
                   System.out.println("1) Enter a Student Contact");
                   System.out.println("2) Enter a Family Contact");
                   System.out.println("3) Enter a Contact");
                   System.out.println("4) Display Student Contacts");
                   System.out.println("5) Display Family Contacts");
                   System.out.println("6) Display Contacts");
                   System.out.println("7) Display All Contacts");
                   System.out.println("8) Quit");
                   System.out.println("Selection:");
                   menuOption = sc.nextInt();
                   SchoolContact schoolContact = new SchoolContact();
                   FamilyContact familyContact = new FamilyContact();
                   Contact contact = new Contact();
                   // Implement switch statement to
                   switch (menuOption) {
                   // If user enters 1 to create contact this will be displayed to user
                   case 1:
                        System.out.println("Enter The First Name of The Student");
                        schoolContact.setFirstName(sc.next());     
                        System.out.println("Enter The Last Name of The Student");
                        schoolContact.setLastName(sc.next());
                        System.out.println("Enter the Student ID of this person: 900");
                        schoolContact.setStudentId(Integer.parseInt("900" + sc.next()));
                        System.out.println("G)Enter The GPA For This Student");
                        System.out.println("H)Enter The Number Of Completed Credit Hours");
                        menuOption2 = sc.next().toUpperCase();
                        studentData = menuOption2.charAt(0);
                        // Prompts the user for the next choice
                        if (studentData == 'G') {
                             System.out.println("GPA: ");
                             gpa = sc.nextDouble();
                             //create the Data object
                             Data data = new Data();
                             data.setStudentGPA(gpa);
                             //add it to the contact
                             schoolContact.setData(data);
                             else if (studentData == 'H') {
                                  System.out.println("Hours: ");
                                  creditHours = sc.nextInt();
                                  //create the Data object
                                  Data data = new Data();
                                  data.setStudentCreditHours(creditHours);
                                  //add it to the schoolcontact
                                  schoolContact.setData(data);
                                  else {
                                       System.out.println("Invalid Entry");
                        System.out.println("Enter The Phone Number of This Student");
                        System.out.println("(###)-###-####: ");
                        area = sc.nextInt();
                        prefix = sc.nextInt();
                        suffix = sc.nextInt();
                        //create the phone object
                        Phone_Number studentPhone = new Phone_Number(area, prefix,     suffix);
                        //add it to the Schoolcontact
                        schoolContact.setPhone(studentPhone);
                        //store info in an array
                        schoolContactInfo[ studentContactsSoFar ] = schoolContact;
                        //increase the counter to point to the next free location (if any)
                        studentContactsSoFar++;
                        break;
                   case 2:
                        System.out.println("Enter the First Name of The Contact");
                        familyContact.setFirstName(sc.next());     
                        System.out.println("Enter The Last Name of The Student");
                        familyContact.setLastName(sc.next());
                        System.out.println("Enter The Relationship of This Contact");
                        System.out.println("A) SISTER");
                        System.out.println("B) BROTHER");
                        System.out.println("C) MOTHER");
                        System.out.println("D) FATHER");
                        System.out.println("E) OTHER");
                        menuOption3 = sc.next();
                        familyRelationOption = menuOption3.charAt(0);
                        if (familyRelationOption == 'A') {
                             System.out.println("Relationship: SISTER ");
                             familyContact.setRelationType(FamilyContact.RelationType.SISTER);
                             else if (familyRelationOption == 'B') {
                             System.out.println("Relationship: BROTHER ");
                             familyContact.setRelationType(FamilyContact.RelationType.BROTHER);
                                  else if (familyRelationOption == 'C') {
                                       System.out.println("Relationship: MOTHER ");
                                       familyContact.setRelationType(FamilyContact.RelationType.MOTHER);
                                       else if (familyRelationOption == 'D') {
                                            System.out.println("Relationship: FATHER ");
                                            familyContact.setRelationType(FamilyContact.RelationType.FATHER);
                                            else if (familyRelationOption == 'E') {
                                                 System.out.println("Relationship: OTHER ");
                                                 familyContact.setRelationType(FamilyContact.RelationType.OTHER);
                        System.out.println("Enter The Phone Number of This Contact");
                        System.out.println("(###)-###-####: ");
                        area = sc.nextInt();
                        prefix = sc.nextInt();
                        suffix = sc.nextInt();
                        //create the phone object
                        Phone_Number familyContactNumber = new Phone_Number(area, prefix,     suffix);
                        //add it to the familyContact
                        familyContact.setPhone(familyContactNumber);
                        //store info in an array
                        familyContactInfo[ familyContactsSoFar ] = familyContact;
                        //increase the counter to point to the next free location (if any)
                        familyContactsSoFar++;
                        break;
                   case 3:
                        System.out.println("Enter The First Name of The Contact");
                        contact.setFirstName(sc.next());     
                        System.out.println("Enter The Last Name of The Contact");
                        contact.setLastName(sc.next());
                        System.out.println("Enter The Phone Number of This Contact");
                        System.out.println("(###)-###-####: ");
                        area = sc.nextInt();
                        prefix = sc.nextInt();
                        suffix = sc.nextInt();
                        //create the phone object
                        Phone_Number contactNumber = new Phone_Number(area, prefix,     suffix);
                        //add it to the contact
                        contact.setPhone(contactNumber);
                        //store info in an array
                        contactInfo[ contactsSoFar ] = contact;
                        //increase the counter to point to the next free location (if any)
                        contactsSoFar++;
                        break;
                   case 4:
                        System.out.println("-----Student Contacts-----");
                        //print each stored contact
                        for( int i = 0 ; i < studentContactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + schoolContactInfo.toString() + "\n");
                        break;
                   case 5:
                        System.out.println("-----Family Contacts-----");
                        //prints each stored contact
                        for( int i = 0 ; i < familyContactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + familyContactInfo[i].toString() + "\n");
                        break;
                   case 6:
                        System.out.println("-----Contacts-----");
                        //prints each stored contact
                        for( int i = 0 ; i < contactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + contactInfo[i].toString() + "\n");
                        break;
                   case 7:
                        System.out.println("Calling Case 7");
                        for( int i = 0 ; i < contactsSoFar ; i++ )
                             System.out.println( (i+1) + ". " + contactInfo[i].toString() + "\n");
                        break;
                   case 8:
                        System.out.println("Program Ended");
                        break;
              } while (menuOption != 8);

    how would I go in printing the contacts from one array, then the next array and so on?
    case 7:
        System.out.println("Calling Case 7");
        for( int i = 0 ; i < studentContactsSoFar ; i++ ) {
            System.out.println( (i+1) + ". " + schoolContactInfo.toString() + "\n");
    for( int i = 0 ; i < familyContactsSoFar ; i++ ) {
    System.out.println( (i+1) + ". " + familyContactInfo[i].toString() + "\n");
    for( int i = 0 ; i < contactsSoFar ; i++ ) {
    System.out.println( (i+1) + ". " + contactInfo[i].toString() + "\n");
    break;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Easy question about Reformatting

    Hello all,
    I am trying to reformat my HD after I have deleted Windows XP off of a partition. The reason for this is an upgrade to Vista and a larger allotment of HD space. My question is:
    I am using Backup v3.1.1. (v369) and I have FULL backup files of my Home folder, and my Music folder (as backup for my backup) for all my iTunes libraries. These are located on a portable HD. Are these the correct files to have backed up in order to have my MAC the way it was before I started the process? If so, then once the reformatting is complete, how do I get it all back onto my MAC permanently? Will all my apps and tweaks work as before?
    I am sure this is a simple question, however, I have never had to do this with a MAC, and I want to make sure I have all bases covered before I begin this. Any other comments or advice would be greatly appreciated.
    Thanks All!

    You call this an easy question ???
    Just messin with ya
    Your home folder is the most important folder containing your music, documents, preferences etc. but a lot is also stored in the system folder and library folder outside your home folder, if you want to be ensured of an exact copy of your current system the best way to go at this is to clone your system partition.
    The app i use for this is carbonCopyCloner
    http://www.bombich.com/software/ccc.html
    To add to this.. i've heard there is software for the mac that allows you to make adjustments to the size of your partitions without having to format the drive, i don't know the names of these products but i do know that it's very risky to use them, if you decide to use an app like that make sure you have proper backups of everything just in case it goes wrong.
    Message was edited by: Pr0digy V.

  • Quick (hopefully easy) question about rotating video...

    I'm going to be shooting some video soon that I will later be editing with FCP. I'm going to shoot the video on a Canon Vixia HF10 (AVCHD) camcorder.
    In the situation I'll be shooting, with the mount I'll be using, it would be much easier for me to shoot this video with the camera fully upside-down.
    If I shoot the video fully upside down, can I easily rotate it 180 degrees in FCP with no loss of quality?
    Thanks!

    An interesting thing about video that is shot upside down is the ballistics of the camera movement can be weirdly disconcerting. For instance, if it's a helmet- or wing-style mount, pans and tilts just feel odd.
    As Eric suggests, flipping the image 180 degrees is easy but practice and evaluate.
    bogiesan

  • A question about arrays (brace yourself this is a long post)

    I am working on an assignment that is about generating a random rabbit race by using arrays:
    Rabbit Race
    Write a program to simulate a race between 4 rabbits (numbered 0 to 3). Initially, all contestants are at the start of the race track (position 0) and must race on a 20 meter track (positions numbered 0 to 19). Each participant has its own technique; some run fast, but are sometimes lazy; while others run slowly but steadily. All rabbits make 1 movement one after the other and the one who arrives at the end of the track before the others, wins the race. Here are the rabbit?s strategies :
    At each turn, rabbit 0:
    - sleeps (so does not run), 50% of the time;
    - runs 4 meters, 30% of the time;
    - runs 3 meters, 20% of the time.
    At every turn, rabbit 1 runs 2 meters.
    At each turn, rabbit 2:
    - sleeps, 30% of the time;
    - runs 3 meters, 70% of the time.
    At each turn, rabbit 3:
    - runs 1 meter, 80% of the time;
    - runs 10 meters, 20% of the time.
    The difficulty in the race is that the track has little slippery hills. So after each movement, rabbits can slide down a hill bringing them either closer to the finishing line, or closer to the starting line. How much they slide and in what direction depends on the slope of the hill at their current position, and how many meters they ran during this turn. Each position (or meter) of the hill has a slope represented by an integer between -3 and +2. If the slope is :
    - zero : then, there is no hill at this position and rabbits that reach this position stay there.
    - a negative integer : then, there is a declining side of a hill at this position, and all rabbits reaching this position will slide down
    to a new position that is closer to the finishing line. The new position will be the current position minus the slope times the number of meters the rabbit ran.
    For example, assume a rabbit was in position 10, then ran 5 meters to position 15. If the slope at position 15 is -2, then the new position of the rabbit will be 15 - (-2 x 5) = 25.
    - a positive integer : then, there is a rising side of hill at that position, and all rabbits reaching this position will slide down to a new position that is closer to the starting line. The new position will be the current position minus the slope times the number of meters the rabbit ran.
    For example, assume a rabbit was in position 10, then ran 5 meters to position 15. If the slope at position 15 is +1, then the new position of the rabbit will be 15 - (+1 x 5) = 10.
    Notes on the race:
    - Rabbits have 40 turns to reach the finish line. If after 40 turns no one has managed to reach position 19 (or beyond), then the race is cancelled and no winner is declared.
    - A rabbit?s position can never go below 0. If, after calculating a rabbit?s position, you arrive at a negative position (ex. position -3), then consider that it is at position 0.
    - Consider that any position outside the track (ex. position 0 or position 20) has a slope of 0.
    - If a rabbit reaches position 19 (or goes beyond it), it does not immediately win the race. If any other rabbit reaches position 19 (or beyond) during the same turn, then there is a tie.
    - If at the same turn, one rabbit reaches position 19, and another reaches a position higher than 19, the second rabbit does not win the race because it went further than the first. They both win.
    Ok I know this is long and boring to read but I already completed the majority of the assignment here is my code:
    public class Assignment_3 {
        public static void main (String args[])
             int[] position = new int[20];
             int[] slope = new int[20];
             int[] moveRabbit = new int[4];
                   moveRabbit[1] = 2;
             int[] currentPosition = new int[4];
             int currentPositionandSlope = 0;
             for (int i=0;i<position.length;i++)
             {     position=i;
              System.out.print(position[i] + " ");
         System.out.println();
         for (int i=0;i<(position.length-5);i++)
         {     slope[i]=(int) (-3 + Math.random()*5);
         for (int i=0;i<position.length;i++)
              System.out.print(slope[i] + " ");
         System.out.println();
         for (int turn=1;turn<=40;turn++)
              int randomNb0 = (int) (Math.random () * 100);
    int randomNb2 = (int) (Math.random () * 100);
    int randomNb3 = (int) (Math.random () * 100);
              if (randomNb0<=50)
                   moveRabbit[0] = 0;
              else if (randomNb<=30)
                   moveRabbit[0] = 4;
              else
              moveRabbit[0] = 3;
              if (randomNb2<=30)
                   moveRabbit[2] = 0;
              else
              moveRabbit[2] = 3;
              if (randomNb3<=80)
                   moveRabbit[3] = 1;
                   else
              moveRabbit[3] = 10;
    for (int j=0;j<=3;j++)           
    System.out.println ("Rabbit" + j + " is at position " + position[currentPosition[j]]);
    if (slope[currentPosition[j]+moveRabbit[i]] < 0)
         currentPositionandSlope = position[currentPosition[j]+moveRabbit[j]] - (slope[currentPosition[j]+moveRabbit[j]] * moveRabbit[j]);
    else if (slope[currentPosition[j]+moveRabbit[i]] > 0)
         currentPositionandSlope = position[currentPosition[j]+moveRabbit[j]] - (slope[currentPosition[j]+moveRabbit[j]] * moveRabbit[j]);
    else
         currentPositionandSlope = (currentPosition[j]+moveRabbit[j]);
    System.out.println ("it will move by " + moveRabbit[j] + ", but at position " + (position[currentPosition[j]] + moveRabbit[j]) + " there is a slope of " + slope[currentPosition[j] + moveRabbit[j]]);
    System.out.println ("so it will slip by " + (position[currentPositionandSlope] - moveRabbit[j]) + " positions, and end up at position " + position[currentPositionandSlope]);
    currentPosition[j] += currentPositionandSlope;
    *Ok basically my question is that in the assignment there is an example output where the rabbit is at position 21 but the array is only 20 in length and my program crashes if i go beyond the array length.*
    The example output is here:
    Welcome to the 4 rabbit race:
    position: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    slopes: 0 0 1 -2 1 0 -1 -1 1 -2 1 0 -1 -1 1 0 0 0 0 0
    TURN #1
    rabbit 0 is at position 0
    it will move by 3, but at position 3 there is a slope of -2
    so it will slip by 6 positions, and end up at position 9
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    rabbit 2 is at position 0
    it will move by 3, but at position 3 there is a slope of -2
    so it will slip by 6 positions, and end up at position 9
    rabbit 3 is at position 0
    it will move by 1, but at position 1 there is a slope of 0
    so it will slip by 0 positions, and end up at position 1
    TURN #2
    rabbit 0 is at position 9
    it will move by 0, but at position 9 there is a slope of -2
    so it will slip by 0 positions, and end up at position 9
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    rabbit 2 is at position 9
    it will move by 3, but at position 12 there is a slope of -1
    so it will slip by 3 positions, and end up at position 15
    rabbit 3 is at position 1
    it will move by 1, but at position 2 there is a slope of 1
    so it will slip by -1 positions, and end up at position 1
    TURN #3
    rabbit 0 is at position 9
    it will move by 3, but at position 12 there is a slope of -1
    so it will slip by 3 positions, and end up at position 15
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    rabbit 2 is at position 15
    it will move by 3, but at position 18 there is a slope of 0
    so it will slip by 0 positions, and end up at position 18
    rabbit 3 is at position 1
    3
    it will move by 10, but at position 11 there is a slope of 0
    so it will slip by 0 positions, and end up at position 11
    TURN #4
    rabbit 0 is at position 15
    it will move by 0, but at position 15 there is a slope of 0
    so it will slip by 0 positions, and end up at position 15
    rabbit 1 is at position 0
    it will move by 2, but at position 2 there is a slope of 1
    so it will slip by -2 positions, and end up at position 0
    *rabbit 2 is at position 18*
    *it will move by 3, but at position 21 there is a slope of 0*
    *so it will slip by 0 positions, and end up at position 21*
    *We have a potential winner...*
    rabbit 3 is at position 11
    it will move by 1, but at position 12 there is a slope of -1
    so it will slip by 1 positions, and end up at position 13
    So yeah :) that's basically my question (all this text for a simple question like that lol)
    If you've managed to get to the end of my post then any guidance on my code would be appreciated too :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I'm not going to read that long post. As suggested, produce an SSCCE
    and paste in the exact, complete error message, and indicate clearly which line causes it.
    I did notice this though:
    Ok basically my question is that in the assignment there is an example output where the rabbit
    is at position 21 but the array is only 20 in length and my program crashes if i go beyond the array length.Either you're misunderstanding something, or the assignment has a typo. If you have an array of length 20, then the indices are 0..19.
    Maybe the instructor is calling index 0 position 1--separating Java's array impelementation details from
    colloquial 1-based counting, so that the rabbit starts at "position 1" (index 0) goes through "position 20"
    (index 19), and when he's done, he's "at postion 21"--i.e., past the finish line, off the end of the course, etc.
    This won't correspond to any index in the array, but can still be considered a logical position in the race. "Oh, he's
    at position 21. He's done. There's nothing more to do with the array, as it has no slot corresponding to
    this 'done' position."
    That's pure speculation on my part. You'll have to ask your instructor or figure out for yourself what's going on.

  • Easy Question about resizing video

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    In my old program "Premiere', to resize and move a video around was very easy. You could adjust the scale and X-Y values numerically, or you could use a Free Transform like in Photoshop. Simply dragging bounding boxes for size and aspect and also dragging the clip to decide it's location.
    The only way I know how to do this in FCP is I double click a clip in the sequence, it loads into the viewer, I go to the Motion Tab and then I can adjust the Scale, which is cool. But then I'm left with the Distort section to adjust position (and aspect if need be). In the Distort section there are 8 numeric fields of info to figure out and fill out just to get one clip in a different position correctly.
    I'm thinking there must be another way to adjust the location (or aspect) of a video clip without spending a bit of time on exact coordinates, I want to eye-ball where I want the clip to go and simply move it there. Is the Distort feature the only way to do this? If not, which is the fastest way to move and change the dimension of a clip.
    Thanks for reading, I hope there is another way, I'm not use to these calculations and they're slowing me down.
    Monty

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    That's because it's not a simple question at all and yet every one of those threads was related to the OP's question. As you discovered, there are lots of ways to interpret "resize," during capture, editing, effects, output, viewing, encoding, printing. But the solution was even simpler than you thought. All you had to do was open the manual or the online help system. Start taking the manuals to the gym with you. FCP is not Premiere. You're going to hate FCP, you're going to love FCP but it will never behave like Premiere beyond the elements of the functional paradigm. Forget Premiere.
    bogiesan

  • A few questions about Arrays and Array Methods.

    I have 2 dimentional arrays in a number of classes, and I wish to pass them about as variables, however, I can only seem to send int[], rather than int[][]. Gives me some compile errors.
    Another thing. How do i get the length of an array?
    I've tried: getLength(object), but it's a 2d array (int[][]), and It's having none of it. How do i get the length of a particular side?

    An object like int[][] only has a single "length", and that is the length of the first dimension. This object is an array that contains arrays of int, and each of those arrays could have a different length. Your 2D array may happen to be rectangular but that isn't a requirement of Java. So you would have to write your own code to find the lengths of the sides. The first side would be theArray.length, the second side would be theArray[0].length, and like that.

  • Easy Question about end jumps

    Here is my menu lay out. Three buttons.
    Play all (Want it to play enire movie)
    Play part one ( Play up to track 6 and return to menu)
    Play part two (Play from track 7 to end)
    Can someone please tell me how to do this correctly? What am I doing Wrong

    Hi Deon - it's hard to say what you are doing wrong if you don't tell us what you are doing!
    What I would do to set this up is place all the footage into a single track, set markers between each section and use stories to define which chapters play when each button is pressed. Your 'play all' button would point to the track itself. Your 'Play part 1' button would point to a story container, inside which I would place chapters 1 to 6. Finally, the remaining chapters would be in a second story and this would be the button target for 'Play part 2'.
    You do not need to have the assets in separate tracks at all - if you want to play a single clip it can be in a single story with just one chapter marker in - each story can have an end jump setting to return back to the menu...
    Hopefully this will help get you on the way, but if not please give as much info about what you have already done so we can start to troubleshoot it with you.

  • Hi, i got some question about arrays.

    My question is how do i auto increase the array size for theList[0] to store the over time if the user enter more than 1 employee.
    static void showPayInfo(int num1 , int num2)
              for(int coloum = 1 ; coloum <= num2 ; coloum++)
                   System.out.print("Enter employee's over time  $: ");
                   ot = CspInput.readDouble();
                   Double = ot;
                   getDouble(Double);
    static double ot , Double;
         static void getDouble(double Double)
              double[] theList = new double[2];
              theList[0] = ot;
         public static void main(String[] args)
              int a;
              System.out.print("How many employees : " );
              a = CspInput.readInt();
              showPayInfo(1,a);
         }

    how to create the list?
    import java.util.ArrayList;
    class testArrayList {
       public static void main(String[] args) {
         ArrayList<String> list1 = new ArrayList<String>();
         // Populate list
         for (int i = 0; i < 5; i++) {
           list1.add("List item " + i);
         // Show list
         for (int i = 0; i < list1.size(); i++) {
           System.out.println(list1.get(i));
    }

  • A question about arrays. Please Help

    Ok here is my question lets say i have a multie varible array such as
    int[][] thisList = new int[3][64];And I have a number of other arrays that are single variable arrays, and which have data stored in them.
    List1[64]
    List2[64]
    List3[64]is there a way i can store all these three list in the multie varible array?
    for example i know i can do this, > Correct me if i am wrong
    List1 = List2; where List1 one now contains all the elements that List2 has.
    but is there a way i can
    us the same format with a multie varible array, to store all three list in it.
    such as thisList[1][] = List1; thisList[2][] = List2[]; Thanks

    for example i know i can do this, > Correct me if i
    am wrong
    List1 = List2; where List1 one now
    contains all the elements that List2 has.There will be one array. Both the List1 and List2 reference variables will point to that same array.
    (By the way, convention in Java is for variables to start with lowercase.)
    >
    but is there a way i can
    us the same format with a multie varible array, to
    store all three list in it.
    such as thisList[1][] = List1; thisList[2][] =
    List2[];
    You can do thisList[1] = List1 if thisList is an int[][] and List1 is an int[]. However, that will not copy any ints. It will just do the same as the above--cause the reference thisList[1] to point to the same array object as List1 does.
    If you want to copy values from one array to another, use System.arraycopy.

  • Quick Easy Question About N580GTX-M2D15D5 Bios

    Hey guys!!
    I just have a real quick and easy (i suppose) question!
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly since the bios date and version remained the same?
    Thanks !

    Quote
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    Quote
    version 70.10.17.00.01
    that's suppose to be, this is the version of the both bioses
    Quote
    & date November 09, 2010
    this is GPU release date, not BIOS date
    Quote
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly
    Get this: https://forum-en.msi.com/index.php?action=dlattach;topic=147603.0;attach=7931
    extract it somewhere, then run info1 , and look for the last line
    Quote
    since the bios date and version remained the same?
    they are not the same, your looking the wrong stuffs

  • Really easy question about DVDs

    I am about to get a new 5g iPod, and I am excited about being able to watch videos on it. But I have a quick question, is it possible to rip DVDs(like you can with CDs) from iTunes?
    Thanks

    This article addresses your question:
    http://docs.info.apple.com/article.html?artnum=302758

  • Very simple and quick question about Arrays

    Hi,
    I have the following code to produce a student grades provessing system. I have got it to store data in the array, i just cant figure out how to add the integers from the row to produce a total. Thats all I want to do create a total from the 6 marks and add a percentage.
    Any help would be greatly appreciated.
    -------------CODE BELOW----------------------
    import java.util.*;
    public class newstudent1_2
    public static void main (String[]args)
    System.out.println ("-----------------------------------------------"); //Decorative border to make the welcome message stand out
    System.out.println (" Welcome to Student Exam Mark Software 1.2"); //Simple welcome message
    System.out.println ("-----------------------------------------------");
    int [][] mark;
    int total_mark;
    int num_students;
    int num_questions = 9;
    Scanner kybd = new Scanner(System.in);
    System.out.println("How many students?");
    num_students =kybd.nextInt();
    mark = new int[num_students][num_questions] ;
    for (int i=0; i<num_students; i++)
    System.out.println("Enter the Students ID");
    String student_id;
    student_id =kybd.next();
    System.out.println("Student "+i);
    for( int j=1; j<num_questions; j++)
    System.out.println("Please enter a mark for question "+j);
    mark[i][j]=kybd.nextInt();
    System.out.print("id mark1 mark2 mark3 mark4 mark5 mark6 mark7 mark8");
    //This section prints the array data into a table
    System.out.println();
    for (int i=0; i<num_students; i++)
    for( int j=0; j<num_questions; j++)
    System.out.print(mark[i][j]+"\t"); //the \t is used to add spaces inbetween the output table
    System.out.println();
    --------------END OF CODE---------------
    Thanks.

    I had to do this same sort of thing for a school assignment but i didnt use an array.
    import java.text.DecimalFormat;
    import TurtleGraphics.KeyboardReader;
    public class grade_avg
         public static void main(String[] args)
              int grade, total = 0, count = 0;
              double avg = 0.0;
              KeyboardReader reader = new KeyboardReader();
              DecimalFormat df = new DecimalFormat("0.00");
         for (;;)
                   grade = reader.readInt("Please enter a grade: ");
              if (grade > 0)
                        total = total + grade;
                        count ++;
              if (grade == 0)
                        avg = total / count;
                        System.out.println("The average is: " + df.format(avg));
                        System.exit(0);
    }output looks like:
    Please enter a grade: 100
    Please enter a grade: 50
    Please enter a grade: 0
    The average is: 75.00

  • Hello and a question about Arrays

    Hello! I am a student working towards a CIS degree, I'm only in my second term, so I have a long way to go still. Next term (starts in November) I'll be starting my first language (Java) so I figured this is a good spot to register and get acquainted with all of you.
    Anyway, right now I'm in a programming logic and design class. In this class we use Pseudocode to get the basic constructs of programming down without doing anything language specific. I just read the chapter that introduces Arrays and had a difficult time following it. Could any of you take a minute and give me your definition of what exactly an array is and how it works? Or maybe point me to a link that might help me? I've got the 'jist' of it, but the book jumps right into algorithms using arrays without much explaination as to what they are.
    Thanks for any response and for helping a programming "n00b".
    -Rawhide

    >
    Hello! I am a student working towards a CIS
    CIS degree, I'm only in my second term, so I have a
    long way to go still. Next term (starts in November)
    I'll be starting my first language (Java) so I
    figured this is a good spot to register and get
    acquainted with all of you.
    Anyway, right now I'm in a programming logic andThink of an array as a series of boxes. These boxes store data for three
    elements. So you would have three boxes that store one element of data.
    So 'this' array has a capacity of three. If you want something bigger,
    you'd create a array with more boxes, say 10. Then your array has a capacity of 10.
    To get to anything from a array, you either need to :
    a) go through all the elements of the array
    b) or actually know the element you want to retrieve.
    The second case is simple enough, you usually just specify the element you want. For example the first element would be zero.(counting starts from zero). The last element would be 9 (10 -1).
    The first case requires some knowledge of looping, you'd generally itterate from the first until the last element of the array, in each and every element that you are at, do the stuff you need to do. This will go on until the end of the array is reached.
    for(int i=0; i<=arraylength;i++ ) {
    do some stuff. like print out to the console.
    I'm not giving you any specific java code because you didn't ask for any and you were doing a course that wasn't language specific. So I figured that may be a simpler explanation(was it?) was in order.
    Let me know if you need clarification.
    and design class. In this class we use Pseudocode to
    get the basic constructs of programming down without
    doing anything language specific. I just read the
    chapter that introduces Arrays and had a difficult
    time following it. Could any of you take a minute
    and give me your definition of what exactly an array
    is and how it works? Or maybe point me to a link that
    might help me? I've got the 'jist' of it, but the
    book jumps right into algorithms using arrays without
    much explaination as to what they are.
    Thanks for any response and for helping a programming
    "n00b".
    -Rawhide

  • Easy question about JScrollPane issue

    The problem is I do not understand why it is not possible, or what I am doing wrong to not be able to initialize a JScrollPane with a variable and call it later, real easy to see in the code below.
    NOTE! I CAN use scrollbars, but only without initializing first, am just trying to understand how to properly do this with initialization or if it is not possible.
    Thank you!!!!
    just look for the First 3 commented sections with stars ******
    import java.awt.Container;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class SquareIntegers extends JApplet {
         // set up GUI and calculate squares of integers from 1 to 10
         public void init() ///all variables below are LOCAL, because used only in "init()" if needed elsewhere make above in the CLASS
                             //OR SAVE VALUES between calls to the class's methods
                // get applet's content pane (GUI component display area)
              Container container = getContentPane();
              container.setLayout(new FlowLayout());
              //creaing a layout because I wanted to add a scroll pane
              //container.setLayout(new BorderLayout());
              // JTextArea to display results
              JTextArea outputArea = new JTextArea(8, 8);
              // JScrollPane myscrollbar = new JScrollPane( outputArea ); //********************this is line 27 why does this along with line 33 NOT work????????
              // attach outputArea to container
              container.add( outputArea);
              //container.add( myscrollbar); ******************************this is Line 33 why does this along with line 277 NOT work????????
              container.add(new JScrollPane( outputArea ));//***********this is Line 34, if I comment out 27/33, and just use this, scrollbars
                                                                     // work correctly, but I have heard/seems better to "initialize variables first"
              int result; // store result of call to method square
              String output = ""; // String containing results
              // loop 10 times
                   for ( int counter = 1; counter <= 10; counter++ ) {
                   // calculate square of counter and store in result
                   result = square( counter );           //***********************uses the CUSTOM method from line 44
                   // append result to String output
                   output += "The square of " + counter +
                   " is " + result + "\n";
                   } // end for structure
         outputArea.setText( output ); // place results in JTextArea
    } // end method init
         // square method definition...***** This is a CUSTOM method creation..... if "Math.sqrt" was used, we would not have to do this
         public int square( int y )
         return y * y;      // return square of y this is RETURNED to the statement in "init()" that originally invoked the
                             // "square()" method - in this case line 32, where RESULT invoked the METHOD, so "result" gets the value of RETURN
                             // if it were "public int square()" that means the method does NOT return a value
    The general format of a method definition is
    return-value-type method-name( parameter-list )
    declarations and statements
    including "return;" or "return EXPRESSION;"
         } // end method square ALL METHODS must always be created inside the CLASS definition, as this one is... notice the closing
              // CLASS bracket below
    } // end class SquareIntegers

    Thank you!!!
    I think I understand...... since the JScrollPane already assigned itself to the JTextArea....
    when "adding" to the parent container, the only necessary component to call was in fact the JScrollPane with the container.add( myscrollbar); I do not know if this is correct, but I thank you for your help, because this definitely confused me, back to studying :)
    I have it 100% operational, just posting this to say thank you that it worked, and it will help further my and possibly others understanding of this.

Maybe you are looking for

  • Verizon doesn't care about its customers

    I have been a customer of Verizons for a long time they used to be the best in customer service and meeting a persons needs, but this has gone away. They no longer care about there customers they only care about making more money off of us. My bill i

  • Request for some assistance

    Hello, I was just sent a Droid Charge and has only had it for about a week and half now in replacement of the Thunderbolt which I had at least 5 replacements of due to problems. I'm very ****** right now because I was sent the Droid Charge where I ha

  • File sharing won't respond

    I recently upgraded and when I try and turn filesharing on, it doesn't respond. The check button stays blank. This is really frustrating. I am also noticing that Airport is working, but in network settings it is shown as a green light, but listed as

  • ACR 7.4 update for CS6

    Updater mechanism (CS6) is not seeing the available ACR 7.4 update.  Any recommendations for access to the update?  Running Mac OS X 10.8.3.  Upon upgragding to CS6, Adobe Application Manager stopped finding available updates.  I have had to manually

  • Without touching the pad the pages start automatically...mail images etc....can't stop them

    is it broken?