Array Help

I am writing a class that extends AbstractList. It is overriding the set(), get(), both add(), remove() , and size() functions. I am having a problem implementing this however. This class needs to create an array of objects that is variably sized, so the size is not set, it can constantly change. I was thinking of using two arrays, one that adds/removes an object, and another that is created afterwards, using System.arraycopy, and would be either 1 element larger or smaller depending on whether add or remove was called. I am just having some trouble implementing this because I have to initialize an array, but that array has to have a set size........ anyone have any ideas?

Well, this is basically how Sun does it in their ArrayList class.
(I ripped this straight from the sources):    public void ensureCapacity(int minCapacity) {
     int oldCapacity = elementData.length;
     if (minCapacity > oldCapacity) {
         Object oldData[] = elementData;
         int newCapacity = (oldCapacity * 3)/2 + 1;
             if (newCapacity < minCapacity)
          newCapacity = minCapacity;
         elementData = new Object[newCapacity];
         System.arraycopy(oldData, 0, elementData, 0, size);
    }The 'elementData' array holds the objects; it is replaced if it can't
contain at least 'minCapacity' elements.
kind regards,
Jos

Similar Messages

  • Loops and Arrays help

    Hi,
    I'm a freshman in college and new to java. I am completely lost and really need help with a current assignment. Here are the instructions given by my teacher...
    Building on provided code:
    Loops and Arrays
    Tracking Sales
    Files Main.java and Sales.java contain a Java application that prompts for and reads in the sales for each of 5 salespeople in a company. Files Main.java and Sales.java can be found here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Main.java
    and here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Sales.java It then prints out the id and amount of sales for each salesperson and the total sales. Study the code, then compile and run the program to see how it works. Now modify the program as follows:
    1. (1 pts) Compute and print the average sale. (You can compute this directly from the total; no new loop is necessary.)
    2. (2 pts) Find and print the maximum sale. Print both the id of the salesperson with the max sale and the amount of the sale, e.g., "Salesperson 3 had the highest sale with $4500." Note that you don't necessarily need another loop for this; you can get it in the same loop where the values are read and the sum is computed.
    3. (2 pts) Do the same for the minimum sale.
    4. (6 pts) After the list, sum, average, max and min have been printed, ask the user to enter a value. Then print the id of each salesperson who exceeded that amount, and the amount of their sales. Also print the total number of salespeople whose sales exceeded the value entered.
    5. (2 pts) The salespeople are objecting to having an id of 0-no one wants that designation. Modify your program so that the ids run from 1-5 instead of 0-4. Do not modify the array-just make the information for salesperson 1 reside in array location 0, and so on.
    6. (8 pts) Instead of always reading in 5 sales amounts, allow the user to provide the number of sales people and then create an array that is just the right size. The program can then proceed as before. You should do this two ways:
    1. at the beginning ask the user (via a prompt) for the number of sales people and then create the new array
    2. you should also allow the user to input this as a program argument (which indicates a new Constructor and hence changes to both Main and Sales). You may want to see some notes.
    7. (4 pts) Create javadocs and an object model for the lab
    You should organize your code so that it is easily readable and provides appropriate methods for appropriate tasks. Generally, variables should have local (method) scope if not needed by multiple methods. If many methods need a variable, it should be an Instance Variable so you do not have to pass it around to methods.
    You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this.
    I'm not asking for someone to do this assignment for me...I'm just hoping there is someone out there patient and kind enough to maybe give me a step by step of what to do or how to get started, because I am completely lost from the beginning of #1 in the instructions.
    Any help would be much appreciated! Thank you!
    Message was edited by:
    Scott_010
    Message was edited by:
    Scott_010

    First ask the person who gave this asignment as to why do you require two classes for this , you can have only the Sales.java class with main method in it . Anyways.
    Let Main.java have a main method which instanciates a public class Sales and calls a method named say readVal() in Sales class.
    In the readVal method of sales class define two arrays i.e ids and sales. Start prompting the user for inputting the id and sales and with user inputting values keep storing it in the respective arrays .. Limit this reading to just 5 i.e only 5 salesPerson.
    Once both the arrays are populated, call another method of Sales class which will be used for all computations and output passing both the arrays.
    In this new method say Compute() , read values from array and keep calculating total,average and whatever you want by adding steps in just this loop. You can do this in readval method too after reading the values but lets keep the calculation part seperate from input.
    You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this. I think this is ur personal stuff , but if you want to use web page , you probably will require to use servlet to read values from the html form passed to the server.

  • Reading from a text file in to an array, help please

    I have the following
    public class date extends Loans{
    public int dd;
    public int mm;
    public int yyyy;
    public String toString() {
    return String.format( "%d,%d,%d", mm, dd, yyyy );
    public class Loans extends Borrowing {
    public String name;
    public String book;
    public date issue;
    public char type;
    public String toString(){
    return String.format( "%s, %s, %s, %s", name, book, issue, type );
    import java.util.Scanner;
    import java.io.*;
    public class Borrowing extends BorrowingList {
    private Loans[] Loaned = new Loans[20];
    if i want to read in from a text file in to that array how do i do it?

    sorry to keep bothering you and thanks loads for your help but now I am getting the following error mesage
    C:\Documents and Settings\MrW\Menu.java:43: cannot find symbol
    symbol : class IOException
    location: class Menu
    }catch(IOException e){
    Note: C:\Documents and Settings\MrW\Borrowing.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    BUILD FAILED (total time: 0 seconds)
    for this line
    }catch(IOException e){                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Populating 1D Array, Help with 1 Error

    Hello,
    I have just about finished a program that implements a .txt file containing a few records. The order is an int customerNumber, string firstName, string lastName, and float balance. The snipplet of code posted below is where I believe the problem lies, I just cant figure out where it is. Im not sure if my counter is not working correctly or what. The problem is that I'll input the customer number of the first record and it will output fine, but when I type in any other customer number, it returns null. It is supposed to return null if the customer number is not found in the array. The snipplet of code is posted below and if needed, i will post the entire program. Thanks for any help and feel free to ask questions:
    import java.util.Scanner;
    import java.io.*;
    public class customerList {
         private int count;
         private customerRecord data[];
         public customerList()
         data=new customerRecord[100];
         count=0;
    public void getCustomerList(String fileName) throws IOException
         while(count<100)
         Scanner scan=new Scanner(new File("/Users/kd/Documents/workspace/Assignment1/src/records.txt"));
              int customerNumber=scan.nextInt();
              String firstName=scan.next();
              String lastName=scan.next();
              float balance=scan.nextFloat();
              data[count]=new customerRecord(customerNumber, firstName, lastName, balance);
              count++;
    public customerRecord getCustomer(int customerNumber)
              for(int i=0; i<data.length; i++)
                   if(data.getCustomerNumber()==customerNumber)
                        return data[i];
              return null;

    ahh, i see....stupid mistake. would it still be 'legal' for me to do:
    public void getCustomerList(String fileName) throws IOException
         Scanner scan=new Scanner(new File("/Users/kevindoster/Documents/workspace/Assignment1/src/records.txt"));
         while(count<100)
              int customerNumber=scan.nextInt();
              String firstName=scan.next();
              String lastName=scan.next();
              float balance=scan.nextFloat();
              data[count]=new customerRecord(customerNumber, firstName, lastName, balance);
              count++;
    }or is there a problem with my limitations in the while loop

  • New Builder needs some info K9A Plat. RAID Array help

    This is a new build AMD 64x2 6000+, K9A platinum, Lite On DVD Re Writeable SATA, 2x74Gig WD Raptors in Raid 0, Asus X1950 pro Thermaltake 700 W PSU Crossfire cert.
    BIOS registered my drives, Built array PC Rebooted, Installing Win XP pro Hit F6 install drivers, Format drives, Then before Install  It says that :setup cannot copy the file ahcix86.inf.
    If I skip it, it will install XP but when I try to boot from the hard drive It starts to load XP but crashes to the blue screen of death
    *** Stop: 0x0000007BC ( 0xF78A2524, 0xC0000034, 0x00000000, 0x00000000)
    Has anyone got this error string?
    First RAID array I would very much appreciate any help given.

    Hi!
    Looking at some info on Google and Microsoft site, I cannot find the BC error code, only the error code ending with B. It indicates an error with the boot device. It can be caused by several things.
    Check that you are using the correct device drivers to install Windows
    Also, check the installation CD. It could be that the disk was damaged and that you are missing a crucial file because of that
    You can also try installing Windows again and choose to recover the previous installation.
    If this all does not help, try installing Windows on a single HDD (no raid) to see if that will work.

  • Comparing arrays - help!

    Hello. I've been trying to solve this problem for hours, and I would be most grateful for any help you can give me.
    Basically, I'm trying to compare two arrays of char and tell first how many are the same in the same place (I can do that) and then how many are the same but not in place. However, if there are two of one char in one array, and one of the same char in the other, I only want to count it once.
    The problem is, I can't figure out how to do this. I'm using for loops and then setting the char to 0 if it finds a match. This doesn't work. I tried using a series of if statements but I got weird run time acceptions sometimes, and when I put in more if statements to combat that, 1.) it got too confusing and 2.) still only worked half the time. So I'm back to the for loops.
    Here's what I have:
    for (int j = 0; j<guess1.length; j++){
    for(int k = 0; k<code1.length; k++){
    if(code1[k]== guess1[j]){
    code1[k]=0;
    guess1[j] = 0;
    almost = almost + 1;
    So if the code is BBYG and the guess is BWWY, it should return 1 correct and one almost. It will return the one correct, but then return 3 for the almost. It looks at the B in guess which already returned the correct and find it an almost against both B's. When it should have been set to 0 in the correct for loop.
    Sorry, I ramble a bit. Hope you can help!
    Thanks.

    You're gonna love this.
    Unless you have some annoying and patently backward lecturer who wants you to everything the hard way then get ye nose into:
    1. the Collections framework.
    http://java.sun.com/docs/books/tutorial/collections/index.html
    2. and the Collections class itself.
    http://java.sun.com/javase/6/docs/api/java/util/Collections.html
    Hint: a Map can be used to find the distinct items in a list.

  • Boolean Array-- Help Plz Urgent

    Can i create and initialize an array of booleans like this ?
    Boolean[51] Position = true;
    Thanks... Plz help

    This works:Boolean[] bools = {
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true)
    };... and, fortunately, so does this:Boolean[] bools = new Boolean[51];
    java.util.Arrays.fill(bools, new Boolean(true));I hope you find this of some help.

  • JTextField array help

    Hey guys,
    I'm working on a java GUI right now and I've come up with a problem, hopefully you guys can help.
    I have a page that contains 50 text fields in 2 columns, so instead of making 50 lines of text field code, I decided to make an array of text fields and a for loop to cycle through each one (setting sizes, colors, editable, etc). Now the problem I'm running into is I will later down the road like to setText in these but it will be very cumbersome to have to call them by the arrayName[index #]. Just so I can better express what I mean heres is how I have to call each text field right now:
    arrayName[0].setText("1");
    arrayName[1].setText("2");
    This is how I'd like to be able to call each field:
    1stTextField.setText("1");
    2ndTextField.setText("2");
    Is there anyway I can make it so I can make an array of JTextFields and still be able to call an individual text field inside the array by name? If not, is there a way to point to another variable such as making
    1stTextField = arrayName[0] ;
    2ndTextField = arrayName[1];
    Thanks for the help guys.

    50 text fields in 2 columns... why not just use a JTable?
    Is there anyway I can make it so I can make an array of JTextFields and still be able to call an individual text field inside the array by name?Try a HashMap
    is there a way to point to another variable such as making
    1stTextField = arrayName[0] ;
    2ndTextField = arrayName[1]; Yes, exactly as you coded it up

  • Fixed Array help!!!

    i have a fixed array colection....how do i return the highest value in the array....but i need it to return its position in the array
    i have the running loop working to return the highest value in my array but i need it to store the position it is in
    double max = value[0];
            for(int i = 0; i < 12; i++)
                if(value[i] > max)
                    max = value;
    thnx alot for ur help!

    So you're saying this does not work?
    int indexOfMax = 0;
    double max = value[0];
    for(int i = 1; i < value.length; i++)
      if(value[i] > max)
        max = value;
    indexOfMax = i;

  • Urgent array help needed! come get some duke points

    this program keeps track of rentals for a shop. Other methods and classes not shown (like Customer, Transaction classes) are also in this program. Every item (created with a constructor in Item class) can hold an array of up to 20 transactions; part of a Transaction object is a rental total, based on a number of rental days * specific rental price for that item rented (backhoe, edger, etc.) If the user presses "t" for total amount of transactions, the following method is called, which calls the getTotalPrice() in another class called Item. My problem here is that even if I enter in transaction amounts, when I press "t", the program just quits, not producing the report and returning me to the main class. I have been over it with the debugger and I am still lost. Below is some selected code; I hope it is sufficient. Please let me know if I need to put up more
    //main
    String input = JOptionPane.showInputDialog(null, "Enter a rental transaction (x)" +
                                                      "\nAdd a customer (c)" +
                                                      "\nAdd an item (i)" +
                                                      "\nReport on a specific item (r)" +
                                                      "\nReport on total dollar amounts of rentals for all items (t)" +
                                                      "\nReport on total rentals for a specific customer (s)" +
                                                      "\nStrike cancel to exit from the program");
              //big huge while
              while (input != null){
                   if (input.equals("x")){
                        rentalTrans();
                   }//if
                   if (input.equals("c")){
                        addCustomer();
                   }//if
                   if (input.equals("i")){
                        addItem();
                   }//if
                   if (input.equals("r")){
                        specificItemReport();
                   }//if
                   if (input.equals("t")){
                        allItemReport();
                   }//if
                   if (input.equals("s")){
                        customerReport();
                   }//if
                   input = JOptionPane.showInputDialog(null, "Enter a rental transaction (x)" +
                             "\nAdd a customer (c)" +
                             "\nAdd an item (i)" +
                             "\nReport on a specific item (r)" +
                             "\nReport on total dollar amounts of rentals for all items (t)" +
                             "\nReport on total rentals for a specific customer (s)" +
                             "\nStrike cancel to exit from the program");
    //allItemReport()
    public static void allItemReport(){ //menu item t
              Item temp = null;
              for (int index = 0; index < items.length; index++){
                   temp = items[index];
              }//for
              JOptionPane.showMessageDialog(null, "Total rental transactions to date amount to: $" + temp.getTotalPrice());
    //Item Class
    public String getTotalPrice() {
              double total = 0;
              String output = "";
              for (int i = 0; i < trans.length; i++) {
                   if (trans[i] == null) {
                        if (i == 0) {
                             output = "There are currently no transactions.";
                        }// if
                        break;
                   }// if
                   else{
                   total += getPerDayRentalPrice();
                   }//else
              }// for
              output+= total;
              return output;
         }//getTotalPrice

    Don't flag your questions as urgent. It's rude. Also don't think that waving with a couple of worthless Dukes is going to get you better/quicker help.
    The reason I respond to your question is because you have explained your problem well and used code tags.
    Try this:class Main {
        public static void main (String[] args) {
            String message = "Enter a rental transaction (x)\nAdd a customer (c)" +
                "\nAdd an item (i)\nReport on a specific item (r)\nReport on total "+
                "dollar amounts of rentals for all items (t)\nReport on total rentals"+
                " for a specific customer (s)\nStrike cancel to exit from the program";
            String input = JOptionPane.showInputDialog(null, message);
            while(input != null){
                if (input.equals("x")) rentalTrans();
                else if (input.equals("c")) addCustomer();
                else if (input.equals("i")) addItem();
                else if (input.equals("r")) specificItemReport();
                else if (input.equals("t")) allItemReport();
                else if (input.equals("s")) customerReport();
                else System.out.println("Invalid option!");
                input = JOptionPane.showInputDialog(null, message);
            System.out.println("Bye!");
        // the rest of your methods ...
    }

  • Printing array help please!

    Hi, I have a problem with printing arrays in a certain order. Let me descbribe it, by the way I'm using Java version 1.3 if that helps.
    ok, what I need to do is print out on a single line all the strings found on the command line that end in .java and then I need to print out all the strings found on the command line that end in .class. So say I type on the command line a.java b.class c.java d.class. Then it would print out a.java c.java b.class d.class.
    any help would be appreciated!

    here it goes the complete code:
    * running example: java a.class b.java c.class d.class h.java
    public class Nickal01
         static public void main(String[] args)
              String classes = "";
              for(int i=0; i<args.length; i++)
                   if(args.endsWith(".class"))
                        classes += args[i] + " ";
                   else
                        System.out.print(args[i]+" ");
              System.out.println(classes);

  • Javascript array help needed to generate narrative from checkboxes

    For context...  the user will indicate symptoms in cardiovascular section, selecting "deny all", if none of the symptoms apply.  The narrative sub-form needs to processes diagnosis sub-form and generate text that explains the symptoms in a narrative form.  For example, if the user selects "deny all" in the cardiovascular section, the Cardiovascular System Review field would have:  "The patient denies:  High Blood Pressure, Low Blood Pressure.  The logic associated with the narrative needs to account for "deny all" and all the variations of selections.
    I have what I think is a pretty good start on the logic, but would like some help with the following:
    1) loading selected fields into the cv_1s array
    2) loading fields not selected into the cv_0s array
    3) generating the narrative
    See "phr.narrative.cv_nar::calculate - (JavaScript, client)" for the coding I've done thus far.  Feel free to comment on any efficiency opportunities you see.  I have a SAS programming background, but I'm new to Javascript.  Thanks...
    Rob

    Hi Rob,
    One approach would be to give your checkboxes the same name so they can then be referenced as a group and use the caption as the source of your text, so you shouldn't have to duplicate the text and will make it easier to add more later.
    Attached is a sample doing that.
    Hope it helps.
    Bruce

  • Array help needed!!!

    import java.lang.String;
    import java.io.*;
    import java.io.IOException;
    import java.util.*;
    import java.lang.Boolean;
    class Books
    public static final int SIZE=3;
    // public static final int LOAN;
    // public static final int RETURN;
    //public static final int QUERY;
    static int option;
    String title;
    String author;
    boolean loanStatus;
    String borrowerID;
    Date loanDate;
    Date dueDate;
    Books[]p0=new Books[SIZE];
    static void DisplayMenu()
    System.out.println("===Menu===");
    System.out.println("0 to Exit");
    System.out.println("1 to Borrow a book");
    System.out.println("2 to Return a book");
    System.out.println("3 to Query a book");
    System.out.print("===Your Choice>>");
    public static void main(String[] args)
    throws IOException
    BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    String string;
    Books display =new Books();
    do
    System.out.println("\n\n");
    Date loanDate = new Date();
    Date dueDate = new Date();
    dueDate.setTime(loanDate.getTime() + (long)(24*60*60*1000)*14);
    System.out.println(loanDate);
    System.out.println(dueDate);
    display.DisplayMenu();
    System.out.flush();
    string=stdin.readLine();
    option=Integer.parseInt(string);
    switch(option)
    case 0:
    System.out.println("Exit");
    break;
    case 1:
    //display.displayBookList(Books[] p0)
    display.displayBookList(p0);
    display.loanBook();
    break;
    case 2:
    display.returnBook();
    break;
    }while(option!=0);
    void loanBook() throws IOException {
    BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    String string;
    if(!loanStatus){
    System.out.println("Enter borrower ID: ");
    System.out.flush();
    borrowerID=stdin.readLine();
    loanStatus=true;
    else
    System.out.println("Book is on loan");
    public void Books()
    // Books[]p0=new Books[SIZE];
         loanStatus=false;      
    p0[0]=new Books();
    p0[0].title="Java Software Solution";
    p0[0].author="Lewis Loftus";
    p0[1]=new Books();
    p0[1].title="Java How To Programming";
    p0[1].author="Lewis Loftus";
    p0[2]=new Books();
    p0[2].title="Java";
    p0[2].author="Lewis Loftus";
    void returnBook()
    if( loanStatus)
    loanStatus=false;
    System.out.println("Book is return");
    else
    System.out.println("Book is Not on loan");
    static void displayBookList(Books[] p0)
    //Books display=new Books();
    System.out.println("===Book List===");
    System.out.println("0 Back To Main Menu");
    System.out.println("1 "+p0[0].title);
    System.out.println("2 "+p0[1].title);
    System.out.println("3 "+p0[2].title);
    System.out.print("===Your Choice>>");
    static void processBook(Books[] p0) throws IOException
    System.out.flush();
    string=stdin.readLine();
    option=Integer.parseInt(string);
    switch(option)
    case 0:
    display.DisplayMenu();
    break;
    case 1:
    break;
    case 2:
    display.returnBook();
    break;
    Does anyone know how why i cant access the array???

    Hello,
    After u make p0 as display.p0 inside choice 1 in your main method u can compile the code.
    But still there are some problems in ur code.
    1)when u will try running it and give option as 1.
    ur constructor --- public void Books() will not be called because its not a constructor at all its a method. In any case a constructor can not have a return type.
    if u give a return type to a constructor as given void by u.then that constructor wil be treated as a method and when u costruct the objects default costructor will be called. So ur constructor is never called.Thats why it will
    give u null pointer exception when u try to display the list of books.
    2) if u remove void from ur constructor...
    then also u are calling new Books() constructor again in side new Books() constructor, so it will go in to an infinite loop....
    so be clear what u want to do and then proceed..
    hope this will be of help.
    Amrainder

  • Font array help, please

    Hello
    I am a beginner to Flash and I am wondering if I can create
    an array so that the fields in my online form are input with the
    same size text and font style (10pt Arial normal is fine).
    At the moment, font/size do appear slightly different when
    data is entered in the form, although the Properties panel tells me
    they are the same.
    Would I do it something like this:
    inputs=[name_txt,email_txt,business_txt,country_txt,message_txt];
    for( var elem in inputs) {
    inputs[elem].fontColor = #ffffff;
    inputs[elem].fontStyle = Arial;
    A the moment, the code I have (which is not wonderful) looks
    like this:
    var mainTL:MovieClip = this;
    //start off with submit button dimmed <--I don't actually
    use this
    submit_mc._alpha = 80;
    var dataSender:LoadVars = new LoadVars();
    var dataReceiver:LoadVars = new LoadVars();
    create listener to 'wake up' submit button <--I don't
    actually use this
    var formCheck:Object = new Object();
    formCheck.onKeyUp = function() {
    if (name_txt.text != '' &&
    email_txt.text != '' &&
    business_txt.text != '' &&
    country_txt.text != '' &&
    message_txt.text != '') {
    //clear any alert messages
    alert_txt.text = '';
    //enable the submit button
    submit_mc._alpha = 100;
    } else {
    //remain disabled until all fields have content
    submit_mc._alpha = 80;
    Key.addListener(formCheck);
    /*#######SET STYLES FOR TEXT FIELDS <--I don't actually
    use this#######*/
    //define styles for both normal and focussed
    //set hex values here that work with your site's colors
    var normal_border:Number = 0x000000;
    var focus_border:Number = 0x000000;
    var normal_background:Number = 0xffffff;
    var focus_background:Number = 0xffffff;
    var normal_color:Number = 0x000000;
    var focus_color:Number = 0x000000;
    inputs=[name_txt,email_txt,business_txt,country_txt,message_txt];
    for( var elem in inputs) {
    inputs[elem].border = true;
    inputs[elem].borderColor = normal_border;
    inputs[elem].background = true;
    inputs[elem].backgroundColor = normal_background;
    inputs[elem].textColor = normal_color;
    inputs[elem].onSetFocus = function() {
    this.borderColor = focus_border;
    this.backgroundColor = focus_background;
    this.textColor = focus_color;
    inputs[elem].onKillFocus = function() {
    this.borderColor = normal_border;
    this.backgroundColor = normal_background;
    this.textColor = normal_color;
    Selection.setFocus(name_txt);
    submit_mc.onRelease = function() {
    if (name_txt.text != '' &&
    email_txt.text != '' &&
    business_txt.text != '' &&
    country_txt.text != '' &&
    message_txt.text != '') {
    alert_txt.text='';
    mainTL.play();
    dataSender.name = name_txt.text;
    dataSender.email = email_txt.text;
    dataSender.business = business_txt.text;
    dataSender.country = country_txt.text;
    dataSender.message = message_txt.text;
    dataReceiver.onLoad = function() {
    if (this.response == "invalid") {
    mainTL.gotoAndStop(1);
    alert_txt.text = "Sorry, but your email address appears
    invalid"
    } else if (this.response == "passed") {
    mainTL.gotoAndStop(4);
    //send data to ASP
    dataSender.sendAndLoad("Email.asp", dataReceiver, "POST");
    } else {
    alert_txt.text = "Please complete all fields";
    Many thanks for any help.
    Steve

    I have done that it the Properites panel but when I click
    CTRL and Enter and complete the email form myself, I can see there
    is a difference in fonts in one of the fields - although the
    Properties panel tell me otherwise.
    I just though AS would force the issue.
    Steve

  • Database array help, kind of urgent (checking if element is in array, etc.)

    Here it goes. I have to write a program that firstly loads a .txt file into an array of Student Objects using a for loop. Then I have to display a menu. In this menu, lets say option 1 is chosen, it will ask for the full name of the student. Once the full name is taken it should check to see if it is in the array/file, and if so it will allow the user to add grades and whatnot, and if it isn't there it repors back the error that it could not find it.
    I'm a pretty huge beginner so feel free to laugh away at the code, and I say urgent because I need to get this done and am only using thios forum as a last resort since I seem to be unable to get things going.
    Tell me what you think of what I have so far, did I load the .txt file correctly? I'm pretty sure I did the menu and everything right:
    import java.lang.*;
    import type.lib.Student;
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class StudentDbase2 {
      public static void main(String[] args) throws java.io.IOException{
        PrintStream output = System.out;
        PrintStream fileOutput = new PrintStream(new File("whateveroutput.txt")); // not sure I need this line
        Scanner input = new Scanner(System.in);
        Scanner fileInput = new Scanner(new File("whatever.txt"));
        final int NUMBER_OF_RECORDS = 10;
    Student studentDbase[] = new Student[NUMBER_OF_RECORDS];
        String []menu = { "1 - Add Courses and Grades" ,
                          "2 - View a Course Grade",
                          "3 - View GPA",
                          "4 - View all Courses and Grades",
                          "5 - View student record",
                          "6 - Output entire databse to a file",
                             "Quit - Exit databse"};
    for (int i = 0; i < menu.length; i++)
    System.out.println(menu);
    System.out.print("Enter menu option: ");
    String choice = input.next();
    if (HERE IS WHERE I AM TOTALLY LOST
    while (!choice.equals("Quit"))
    try
    int intChoice = Integer.parseInt(choice);
    System.out.println("Choice was: " + intChoice);
    if ((intChoice < 1) || (intChoice > 4))
    System.out.println("Invalid choice made. Choose again.");
    catch (Exception e)
    System.out.println("Invalid choice made. Choose again.");
    System.out.print("Enter menu option: ");
    choice = input.next();
    }So yeah if you read through it, I mentioned wher eI am lost, and that is when I have to start carrying out the options. I was about to write "if the user inputs 1 then ask for the full name.  That I can do.  But then how to scan it for the name and do the rest is foreign to me.
    Any help/guidance is very much appreciated.  Time is of the essence!  Thanks in advance.
    side note* So far all this does is display the menu, hopefully load the txt file correctly, and allow me to Quit.  The actual meat of the program is where I'm lost.
    another side note* the .txt file contains full names and student numbers
    Edited by: SmallyLarges on Dec 4, 2009 1:05 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    SmallyLarges wrote:
    Here it goes. I have to write a program that firstly loads a .txt file into an array of Student Objects using a for loop. Then I have to display a menu. In this menu, lets say option 1 is chosen, it will ask for the full name of the student. Once the full name is taken it should check to see if it is in the array/file, and if so it will allow the user to add grades and whatnot, and if it isn't there it repors back the error that it could not find it.To add to Melanie's good advice, I would say this: separate the problem from the implementation (ie, what it's going to look like in Java).
    Taking your description above, I've simply repeated it, substituting words where you've made those assumptions or been "wooly" (in brackets) with a more "English" word or suggestion:
    "I have to write a program that firstly loads a .txt file into an (array|*table*) of Student Objects (using a for loop|*<remove>*). Then I have to display a menu. In this menu, lets say option 1 is chosen, it will ask for the full name of the student. Once the full name is taken it should check to see if it is in the (array/file|*table*), and if so it will allow the user to add grades and (whatnot|*<specify>*), and if it isn't there it repors back the error that it could not find it."
    It may seem like a trivial thing, but its a very important point: Don't tie yourself down to an implementation before you have to.
    The nice thing about this is that now you can probably write a bit of "pseudo"-code to see what your main() might look like. When you do this, don't worry about the details, just try to translate the things in your problem description onto paper.
    Perhaps something like:
    load Students
    while the user is not finished
    do
       display menu
       read option chosen
       process option:
          if the option == Quit
          do
             signal that the user is finished
             exit process option
          end
          else if the option == 1
          do
             ask for full name
             if the full name is in our table
                add grades
             else
                report "not found" error
          end
          else if the option == 2
       end of process option
    endDo you see what's happened here? You've broken down the problem into workable chunks; and it's in your own language.
    Now, translating to Java becomes much easier.
    Furthermore, those chunks will often become methods, and your eventual main() method will often look quite similar to your pseudo-code.
    Now, what was that question again....?
    Winston
    Edited by: YoungWinston on Dec 4, 2009 2:32 AM

  • My stupid FOR loop doesnt work to create a new array, help!

    Hello, I need help creating a new integer array that contains exactly one of each element a different array.
    My original array is called co[]
    lets say it has the values: 1213445232
    I want my new array called classArr[]
    for example, it would end up being: 12345
    my integer array is called classArr[]. and i want it to store exactly one of each element from the co[] array. Here is my code. It compiles without errors, but I get out of bounds exception when i run it.
    classArr[0] = co[0];
    int temp = 1;
    for (int k = 0; k < x; k++) { //x is the number or elements in co[]
         for (int j = 0; j < temp; j++) {
              if (classArr[j] != co[k]){
                    classArr[temp] = co[k];
                    temp++;
    System.out.println("Values in new array");
    for (int c = 0; c < temp; c++){
         System.out.println(classArr[c] + " ");
    } Thanks for your help!!!!

    im pretty sure the initialization of the variables are
    set right.Well, without seeing the initialization I doubt I can help you. Try to figure out if it is classArr[temp] or co[k] that causes the exception. (Hint: put them on two different lines.)
    x is the number of elments in the co[] arrayTry replacing it with co.length.
    classArr[] is a dynamic array set to a number, lets
    say it's abcWhat is a "dynamic array" in your terminology? And what is "abc"? Please provide at least the declarations of your arrays.

Maybe you are looking for

  • Error while importing music in iMovie 09 from iTunes 09

    Dear All, I need you help to solve a problem that drives me crazy. I have been working on a new projects for countless hours and had a lot of fun so far. This morning I updated the iTunes software and since then adding music seems impossible. The "+"

  • Which jar to use in order to write add-ons for IE

    Hi, I don't know whether I am asking the correct question but I want to know can I use any jar in order to create add-ons for Internet explorer and, if any, which one? thanks

  • VPN DPD on ASA ios v 8.6.1

    Hello to every one:- 1)i want to know the show command to verify the DPD on ASAs. i tried couple of commands but unable to findout DPD is enable on my ASA. 2) when i try to enable the DPD on ASA the old commands was below. tunnel-group DefaultL2LGrou

  • Problem in playing bg sound ?

    in my app write a code in document class and inside of movieclip.Each movieClip is my category button in wich i am showing animal pics and voice in each frame. So i also code for BG sound playing in document class it works but whenever i click my cat

  • X vs ohci-hcd vs mouse ;-)

    Hello, i have a strange problem. When I start X (XFree or X.org doesnt matter) it disables the mouse (led is turned off) and the whole system crashes. (very often but not everytime) That only happens if ohci-hcd is loaded and (!) my mouse (Logitech)