Simple newbie question about arrays..

Hello all,
I have two arrays declared like so below the class header:
String Players[];
String Final[];
I have a method like the following:
public String[] CollectPlayers() {
Players[0] = new String(txtPlayer1.getString());
return Players;
I am calling this method like so
Final = CollectPlayers();
Basically not working, giving nullpointerexception, but I feel that I am fundamentally not understanding something, so here is what I want...
A method that returns an array and (ideally) use this method directly in creating a ChoiceGroup, like this...
optBull = new ChoiceGroup("Bully", ChoiceGroup.EXCLUSIVE, CollectPlayers(), arrImage);
Is this possible? Any ideas?
Thanks in advance
poncenby

A few points:
- You almost never need to call new String(String).
- You may want to create an ArrayList (dynamic array) and then call toArray(new Players[0]) if you need it to be a fixed array.
e.g.
final List players = new ArrayList();
public List collectPlayers(List players) {
    List finals = new ArrayList();
    for(int i=0;i<players.size();i++) {
        Player player = (Player) players.get(i);
        finals.add(players.getResult());
    return finals;
players.add(new Player("anne"));
players.add(new Player("bob"));
players.add(new Player("fred"));
List finals = collectPlayers(players);

Similar Messages

  • Newbie question about loading servlets on tomcat

    I have what is probably a very basic question about loading simple servlets on to tomcat to test its installation. I have followed instructions from numerous tutorials to the letter but still I can't get it to work.
    I have installed tomcat on win2k in c:\tomcat. I set up the jdk, environment vars (JAVA_HOME, CATALINA_HOME, TOMCAT_HOME) which all point at the correct dirs. I can compile a servlet without errors. I can also place a test jsp and html file into the root directory and they both work fine.
    However, now I am trying a test servlet and no matter what I do it gives me a 404. I have a servlet class file called "HelloServlet.class" which I placed into the %install_dir%\webapps\ROOT\WEB-INF\classes directory. I try to reference it using this url:
    http://localhost/servlet/HelloServlet
    Tomcat is configured to use port 80 and has been restarted after adding the servlet class file. Does anyone have a clue why this is not working for me?
    Many thanks
    Marc

    You have to add in the web.xml file that it is in the WEB-INF dir, the information about your servlet. An example:
    <web-app>
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping>
    </web-app>

  • Newbie Question about FM 8 and Acrobat Pro 9

    Hello:
    I have some dcouments that I've written in FM v8.0p277. I print them to PDF so that I can have a copy to include on a CD and I also print some hard copies.
    My newbie question is whether there is a way to create a  PDF for hard copy where I mainitain the colors in photos and figures but that the text that is hyperlinked doesn't appear as blue. I want to keep the links live within the soft copy. Is there something I can change within Frame or with Acrobat?
    TIA,
    Kimberly

    Kimberly,
    How comes the text is blue in the first place? I guess the cross-reference formats use some character format which makes them blue? There are many options:
    Temporarily change the color definition for the color used in the cross-reference format to black.
    Temporarily change the character format to not use that color.
    Temporarily change the cross-reference definition to not used that character format.
    Whichever method you choose, I would create a separate document with the changed format setting and import those format into your book, create the PDF and then import the same format from the official template.
    - Michael

  • 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;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Newbie question about saving files

    Hi all,
    A newbie question here, and maybe it is a dumb question, but I can't get my head around this and sofar found no answer in the forums here.
    When I save a file on my macbook, I can only save it to "top" folders.
    What I mean is I try to save a file for instance to documents/worddocs/lyrics just to say something, then I have to save the file first to documents, and the move it to the lyrics folder via finder or move it to :worddocs folder and then move it again to the lyrics folder. Hope you still get my drift here
    Is there a way to just save it to the subfolders without going through all this moving around?
    Thanks in advance for any advice
    Peter

    When you click File>Save As, you will see the Save As window pop up. At the top, you will see a box entitled Save As, which has a space for your to enter the file name. To the right of this box is an arrow pointing down. Click it. The full file hierarchy will be seen. Then you can save directly to the file you want.
    Hope this helps.
    Don

  • 2 newbies question about diskgroups

    Hi gurus,
    I have 2 newbies question:
    Im working in a RAC Database (11.2.0.3) on Redhat 5.3 with some disk groups. One of this groups have 6 disks on it with different space (134, 236G, 236G, 185G, 185G and 185G).
    My questions are:
    1) What would be happend when the lower space disk will be full?
    2) At this moment the diskgroups are at 45% so i was thinking to change their spaces to have all with the same space (around 193G each), it would create any problem? i should restart database or can do it with database up?
    Thanks

    if a disk is filled, what would happen? could i resize the disks with same size without stop database and without affecting the data stored within each disc?
    By the word 'disk' I assume you mean LUN . When a LUN in a disk group is filled, ASM will use the remaining LUNs to store the data. You should always use LUNs of uniform size to avoid uneven I/O .
    could i resize the disks with same size without stop database and without affecting the data stored within each disc
    You can get the Unix/Storage team to allocate more LUNs for this Server. Once these LUNs are added , check if the following pre-reqs are met for the LUN which is yet to be added to the disk group
    v$asm_disk.HEADER_STATUS = 'CANDIDATE'
    v$asm_disk.PATH = /dev/rdsk/youLUNname
    v$asm_disk.NAME will be NULL
    Now you can add the LUNs using
    alter diskgroup DATA_DG01 add disk '/dev/rdsk/youLUNname' rebalance power 4 ; wait for rebalance to finish (check status in V$ASM_OPERATION)
    Yes. The above can be done without stopping the DB. It won't affect the stored data either.

  • Two (too much?) newbies questions about KT3 Ultra 2

    Goodmorning all.
    I've bought a KT3 Ultra2 (MS-6380E) motherboard and i've two questions about it.
    First of all I need to buy the optional S-Bracket to use my SPDif sound sistem... where can i buy it in Italy or in Internet?
    In second i've to know the highest processor my MB support becouse i have to upgrade my PC.
    Can U help me?
    Tha a lot and sorry for disturb.
    Hallo.

    Hello,
    question 2, not sure about question 1,
    http://www.msi.com.tw/program/products/mainboard/mbd/pro_mbd_cpu_support_detail.php?UID=341&kind=1
    You may need this BIOS update too.
    http://www.msi.com.tw/program/support/bios/bos/spt_bos_detail.php?UID=341&kind=1

  • 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

  • Newbie question about using vectors and arrays

    I'm fairly new to JME development and java in general. I need some help in regards to Vectors and 1 dimensional arrays. I'm developing a blackberry midlet and am saving the queried info i pull back from my server side application with each record saved into the array and subsequently each array saved as an element in the vector, thereby creating a 2D "array".
    However I'm having a problem accessing the elements in the array. Here is a sample of what I mean and where I get stuck:
    Vector _dataTable = new Vector(1, 1);
    String[] r1 = {"a", "b", "c", "d"};
    String[] r2 = {"1", "2", "3", "4"};
    _dataTable.addElement(r1);
    _dataTable.addElement(r2);
    Object temp = _dataTable.elementAt(0); //Save the element as an new object for useNow how do I access the particular indexes of the element of the temp object? Do i need to caste it to an array? Is there another more efficient/easier way I should be storing my data? Any help would be great!
    Edited by: Sotnem2k1 on Apr 1, 2008 7:50 AM
    Edited by: Sotnem2k1 on Apr 1, 2008 7:51 AM

    Thanks for the feedback newark. I have this scenario below:
    // Class for my 1D array
    public class OneRecord {
        private String[] elementData = new String[4];
        public OneRecord() {   
            elementData[0] = null;
            elementData[1] = null;
            elementData[2] = null;
            elementData[3] = null;
        public OneRecord(String v1, String v2, String v3, String v4) {   
            elementData[0] = v1;
            elementData[1] = v2;
            elementData[2] = v3;
            elementData[3] = v4;
        public void setElement(int index, String Data) {
            elementData[index] = Data;
        public String getElement(int index) {
            return elementData[index];
    } Then in my main app I have:
    Vector _dataTable = new Vector(1, 1);
    OneRecord currRecord = new OneRecord("a", "b", "c", "d");
    _dataTable.addElement(currRecord);
    OneRecord temp = (OneRecord)_dataTable.elementAt(1);
    System.out.println(temp.getElement(0)); Are there more efficient data structures out there to save queried data from a server side app? Like I said, i'm still trying to learn the most efficient techniques of coding...esp for the Blackberry. Any suggestions would be great!

  • 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.

  • Please, help a newbie:  Question about animating expanding containers

    Hi All,
    Short Version of my Question:
    I'm making a media player that needs to have an animation for panels sliding up and down and left and right, and the method I've been using to do this performs far slower than the speed I believe is possible, and required. What is a fast way to make a high performance animation for such an application?
    Details:
    So far, to do the animation, I've been using JSplitPanes and changing the position of the divider in a loop and calling paintImmediately or paintDirtyRegion like so:
    public void animateDividerLocation( JSplitPane j, int to, int direction) {
    for(int i=j.getDividerLocation(); i>=to; i-=JUMP_SIZE) {
    j.setDividerLocation(i);
    j.validate();
    j.paintImmediately(0, 0, j.getWidth(), j.getHeight());
    The validate and paintImmediately calls have been necessary to see any changes while the loop is going. I.e., if those calls are left out, the components appear to just skip right to where they were supposed to animate to, without having been animated at all.
    The animation requirement is pretty simple. Basically, the application looks like it has 3 panels. One on the right, one on the left, and a toolbar at the bottom. The animation just needs to make the panels expand and contract.
    Currenly, the animation only gets about, say, 4 frames a second on the 800 MHz Transmeta Crusoe processor, 114 MB Ram, Windows 2000 machine I must use (to approximate the performance of the processor I'll be using, which will run embedded Linux), even though I've taken most of the visible components out of the JPanels during the animation. I don't think this has to do with RAM reaching capacity, as the harddrive light does not light up often. Even if this were the case, the animation goes also goes slow (about 13 frames a second) on my 3 GHz P4 Windows XP if I keeps some JButtons, images etc., inside the JPanels. I get about 50 frames/sec on my 3 GHz P4, if I take most of the JButtons out, as I do for the 800 MHz processor. This is sufficient to animate the panels 400 pixels across the screen at 20 pixels per jump, but it isn't fast or smooth enough to animate across 400 pixels moving at 4 pixel jumps. I know 50 frames/sec is generally considered fast, but in this case, there is hardly anything changing on the screen (hardly any dirty pixels per new frame) and so I'd expect there to be some way to make the animation go much faster and smoother, since I've seen games and other application do much more much faster and much smoother.
    I'm hoping someone can suggest a different, faster way to do the animation I require. Perhaps using the JSplitPane trick is not a good idea in terms of performance. Perhaps there are some tricks I can apply to my JSplitPane trick?
    I haven't been using any fancy tricks - no double buffering, volatile images, canvas or other animation speed techniques. I haven't ever used any of those things as I'm fairly new to Swing and the 2D API. Actually I've read somewhere that Swing does double buffering without being told to, if I understood what I read. Is doing double buffering explicitly still required? And, if I do need to use double buffering or canvas or volatile images or anything else, I'm not sure how I would apply those techiniques to my problem, since I'm not animating a static image around the screen, but rather a set of containers (JSplitPanes and JPanels, mostly) and components (mostly JButtons) that often get re-adjusted or expanded as they are being animated. Do I need to get the Graphics object of the top container (would that contain the graphics objects for all the contained components?) and then double buffer, volatile image it, do the animation on a canvas, or something like that? Or what?
    Thanks you SO much for any help!
    Cortar
    Related Issues(?) (Secondary concerns):
    Although there are only three main panels, the actual number of GUI components I'm using, during the time of animation, is about 20 JPanels/JSplitPanes and 10 JButtons. Among the JPanels and the JSplitPanes, only a few JPanels are set to visible. I, for one, don't think this higher number of components is what is slowing me down, as I've tried taking out some components on my 3GHz machine and it didn't seem to affect performance much, if any. Am I wrong? Will minimizing components be among the necessary steps towards better performance?
    Anyhow, the total number of JContainers that the application creates (mostly JPanels) is perhaps less than 100, and the total number of JComponents created (mostly JButtons and ImageIcons) is less than 200. The application somehow manages to use up 50 MBs RAM. Why? Without looking at the code, can anyone offer a FAQ type of answer to this?

    You can comment out the lines that add buttons to the panels to see the behavior with empty panels.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.Timer;
    public class DancingPanels
        static GridBagLayout gridbag = new GridBagLayout();
        static Timer timer;
        static int delay = 40;
        static int weightInc = 50;
        static boolean goLeft = false;
        public static void main(String[] args)
            final GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.fill = gbc.HORIZONTAL;
            final JPanel leftPanel = new JPanel(gridbag);
            leftPanel.setBackground(Color.blue);
            gbc.insets = new Insets(0,30,0,30);
            leftPanel.add(new JButton("1"), gbc);
            leftPanel.add(new JButton("2"), gbc);
            final JPanel rightPanel = new JPanel(gridbag);
            rightPanel.setBackground(Color.yellow);
            gbc.insets = new Insets(30,50,30,50);
            gbc.gridwidth = gbc.REMAINDER;
            rightPanel.add(new JButton("3"), gbc);
            rightPanel.add(new JButton("4"), gbc);
            final JPanel panel = new JPanel(gridbag);
            gbc.fill = gbc.BOTH;
            gbc.insets = new Insets(0,0,0,0);
            gbc.gridwidth = gbc.RELATIVE;
            panel.add(leftPanel, gbc);
            gbc.gridwidth = gbc.REMAINDER;
            panel.add(rightPanel, gbc);
            timer = new Timer(delay, new ActionListener()
                    gbc.fill = gbc.BOTH;
                    gbc.gridwidth = 1;
                public void actionPerformed(ActionEvent e)
                    double[] w = cycleWeights();
                    gbc.weightx = w[0];
                    gridbag.setConstraints(leftPanel, gbc);
                    gbc.weightx = w[1];
                    gridbag.setConstraints(rightPanel, gbc);
                    panel.revalidate();
                    panel.repaint();
            JFrame f = new JFrame("Dancing Panels");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(panel);
            f.setSize(400,300);
            f.setLocation(200,200);
            f.setVisible(true);
            timer.start();
        private static double[] cycleWeights()
            if(goLeft)
                weightInc--;
            else
                weightInc++;
            if(weightInc > 100)
                weightInc = 100;
                goLeft = true;
            if(weightInc < 0)
                weightInc = 0;
                goLeft = false;
            double wLeft = weightInc/ 100.0;
            double wRight = (100 - weightInc)/100.0;
            return new double[]{wLeft, wRight};
    }

  • 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

  • Newbie question about Premiere Elements Organizer

    This is a pre-newbie – let’s say “virgin” question. If there is an answer already posted elsewhere, please send me a link.
    I’m about to install Premiere Elements 9 to do some clip editing and animation from still images.  This would be my first attempt to edit clip or do some animation from still images, besides using Windows Media Maker with my HS students. However, I have been a pretty serious photographer for 20+ years with 1,000’s of images which I now work on in PS CS5 Extended and Lightroom 3. I use Adobe Bridge and LR library to catalogue and organize my images. I’d like to continue to use AB / LR Library to organize my new clips and projects. From reading Bill’s posts, it seems I can use Adobe Bridge, copy my original file, resize in Photoshop, and save in a new folder to use for a Premiere project. This would seem to be most intuitive way for me to work. I already have keywords, metadata, actions in PS… etc. But I think Bill is using Premiere Pro, while I’ll be installing Premiere Elements, which comes bundled with Elements Organizer. Do I need to install or use Elements Organizer? What are the advantages/disadvantages or EO?  I guess I’m a little worried about installing the programs and having EO automatically acquire images using presets/defaults that I don’t want to use as well as issues with subfolders, etc. I'm running Windows 7.
    Thanks
    FYI- this is a great animation project
    http://www.thejohnnycashproject.com/#/explore/TopRated

    ziggycat4 wrote:
    I guess I’m a little worried about installing the programs and having EO automatically acquire images using presets/defaults that I don’t want to use as well as issues with subfolders,
    EO doesn't do much with the files themselves, just maintains links to the sources.
    For folders you are best to use the folder view in EO to move them as it doesn't keep track of folder locations when changed in Windows Explorer. From the File options in Bridge I think that is pretty much the same.
    ziggycat4 wrote:
    I would like to get as much input as possible on the advantages/disadvantages of using EO vs say Adobe Bride from others who use Elements Organizer.
    Any insights would be appreciated.
    Can anyone who has used both EO and AB comment on how EO handles missing (hidden) files, syncing issues, computer hanging up or crashing....etc?
    I've only messed around a little with Bridge. But to me it seems lightening fast by comparison to EO. The features Albums and Tags in EO seem much the same as Collections and Keywords in Bridge.
    EO has Face Recognition abilities - getting more sophisticated in each version. I've not seen this feature in Bridge.
    By default EO allows you to open a file in any of:
    Photoshop
    Photoshop Elements
    Premiere Elements
    A single used-defined application (I have mine set to ColorPilot).
    Bridge only seems to link to Photoshop.
    Missing files can be located manually or by allowing EO to search for them.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children

  • Newbie question about C coding and SDK for iPhone app

    Hello,
    I am interested in trying to create an app. However, I have NO experience writing code I already have downloaded and installed the latest version of the SDK.
    I know I have to learn: C, Objective C, and Cocoa.
    I just picked up "C for Dummies" as a starting point. I figured the K&R might be a bit overwhelming to start with. Thing is, "C for Dummies" suggests doing some exercises in Text Edit and then using GCC to compile and test. But, then again, it has a copyright of 2004--long before Snow Leopard.
    My question is, do I really need to do the exercises in Text Edit? Can I just use Xcode for entering the code and testing it? And, any suggestions for learning C and Xcode tutorials are greatly appreciated.
    Thanks!!

    But, I really want to learn coding and not just take the easy route by using Xcode.
    The simplification of using Xcode may have been a bit exaggerated throughout this thread. You will still learn how to program full-on by using Xcode -- it's not like you're taking a shortcut or anything. Well, technically speaking, you are, but Xcode is the expected way to develop on a Mac nowadays -- it's how Apple expects you to develop and how most people are doing so. Should you choose, you can taking a deeper dive into the inner workings of compiling and whatnot by using a text editor and the Terminal, but keep in mind that the extra complexities here could complicate the more important overall goal of learning the basics of how to program. There is absolutely nothing wrong with simply using Xcode for the novice part of your programming days. In fact, it's probably the path I would recommend. Some here might suggest that it is beneficial to learn the intricacies of compiling through the Terminal and whatnot early on, and they are right -- it is beneficial, but the benefits of taking a route (at least for the time being) that allows you to focus on the more pressing issues of learning how to program without having to delve too deeply can be just as beneficial. After all, it's not like you can't go back and learn how to compile via Terminal later on -- that's what I've done (or, rather, am in the process of doing).
    I always thought Terminal was something not to mess with.
    Not so much. Like most things in programming (or life, for that matter), the Terminal is something not to mess with +if you don't know what you're doing+. Basically, it breaks down like this. The GUI that Apple has created for you in Mac OS X (by GUI I mean "graphical user interface" -- the icons and windows and buttons and so forth that you use to perform tasks on your Mac -- in other words, everything outside the Terminal) is geared toward the common user who does not need to access advance aspects of the system's functionality. Consequently, it makes common tasks much simpler to perform, but in the process it hides some of the deeper levels of the system's functionality from the user. This is a good thing, since most people wouldn't know what to do with this functionality and would create problems for themselves if they did have easy access to it. However, for some users who know more about the inner workings of the operating system, there needs to be a way for them to access this functionality, so that they can do certain things (like accessing certain files and performing certain tasks) that they would not be able to do using the Mac OS X GUI -- that's what the Terminal is for. It allows the user to operate the system on a lower level. In other words, it allows you to get closer to the operating system. This is good in a way, because it allows you to perform tasks that you wouldn't otherwise be able to perform by giving you more control over the operating system, but it is also bad in a way, because it can allow you to mess up some of the deeper aspects of your system if you don't know what you are doing. Most people leave the Terminal alone for this reason, and because they have no need of it, but if you want to be a good developer, you're going to have to work with it sooner or later.
    Now, with all that being said, it's not that easy to mess things up using the Terminal. It's not like your system's going to crash if you misspell a command. All in all, the Terminal is very forgiving, but it will do what you tell it to do, even if you tell it to kill itself, and it is for that reason that you need to know what you are telling it before you try to tell it something. If you understand what you are telling the system, than operating on a lower level and being closer to the operating system is completely safe.
    The Mac OS X operating system is based around Unix, so when you are communicating more directly with the operating system by using the Terminal, you are interacting with its Unix core. For this reason, using the Terminal goes hand in hand with understanding Unix. So, if you're going to want to use the Terminal, then I recommend you get a good book on Unix to teach you the basics of Unix commands and shell programming and whatnot. Any book on Unix will do, since more or less everything you learn will be applicable to the Mac OS X's Terminal, but there are a few that are specifically directed to Mac OS X users, and that always makes things easier. Most of these books aren't updated to cover past Tiger, but this really doesn't matter (someone correct me if I'm wrong). A few examples are O'Reilly's "Learning Unix for Mac OS X Tiger" by Dave Taylor or Peachpit Press's "Unix for Mac OS X Tiger" by Matisse Enzer. Also, the book "Unix Programming Environment" by Kernighan and Pike is an excellent book on Unix, although fairly outdated, so I would highly recommend it, although I would recommend it as a supplement to another, more recent, Mac-based Unix book and not as your primary source for learning Unix. The skills you will acquire from these books will help you later if not sooner, so I recommend giving one of them a read at some point, whether you are planning on compiling using the Terminal right now or not.
    Anyways, I hope this helped to clear some of this up for you, and please let us know if you have any further questions.

  • Newbie Questions About Installing Windows with Boot Camp

    The only reason I want to use Windows is to be able to download games from the internet that are not made for Mac only for PC and I have a few questions:
    1. Doing all this installation will anything made for PC work?
    2. I only have Windows XP will that work? And then do all the SP updates after it's installed?
    3. If I have to use Windows XP SP2 is this one a good one to buy?
    http://www.cdsfu.com/index.php?categoryID=87
    4. After everything is installed do I have to use an anti-virus?
    I want to thank you for your help as you can see I really am a newbie.
    Karen

    Hi Karen and welcome to Discussions,
    The only reason I want to use Windows is to be able to download games from the internet that are not made for Mac only for PC and I have a few questions:
    1. Doing all this installation will anything made for PC work?
    Nearly anything. There are some Windows programs using hardware dongles that don't run.
    2. I only have Windows XP will that work? And then do all the SP updates after it's installed?
    You need a Windows XP CD with at least Service Pack 2 (SP2) incorporated.
    3. If I have to use Windows XP SP2 is this one a good one to buy?
    http://www.cdsfu.com/index.php?categoryID=87
    another user round here had already asked about that website.
    Three things about this offer are, at least to me, very suspicious:
    "Microsoft Windows XP Professional Edition With SP2, Full Version on CDR"
    Microsoft never has used CD-R disc (CD-Recordable) for Windows
    "software that does NOT include any COA label or a sticker from the manufacturer"
    There always has to be a sticker, that one puts on the computer on which the Windows license is installed and a COA label as well.
    "VOLUME LICENSE INCLUDED"
    A volume license, from my understanding, was only sold to companys, who install Windows on a larger scale (hundreds of computers) and for that purpose are given only one license-key for all installations.
    Usually this is known as a'corporate license'.
    All in all, I would personally stay away from this offer. It simply doesn't sound legal to me.
    4. After everything is installed do I have to use an anti-virus?
    When running Windows a decent Anti-Virus software is a must.
    I want to thank you for your help as you can see I really am a newbie.
    You're welcome anytime. Hope it helps.
    Karen
    Regards
    Stefan

Maybe you are looking for