Array of linkedlist of object - help! plesse!

I am writing an array of linkedlist and the elements of the linkedlist is an object carrying 2 interger. It didn't compile and the message is as follows:
C:\thesis5>javac testLL2.java
testLL2.java:22: cannot resolve symbol
symbol : variable vertexFanObj2
location: class testLL2
vertexFanObj2 = myLL2[ i].get(j);
^
1 error
My program is as follows:
import java.net.*;
import java.io.*;
import java.util.LinkedList;
public class testLL2 {
public static void main(String[] args) throws IOException {
int myLLLength;
Integer intObj;
LinkedList myLL2 [] = new LinkedList[10];
vertexFan vertexFanObj;
for (int i = 0; i < 10; i++) {
myLL2[ i] = new LinkedList();
for (int j=0; j < 5; j++) {
vertexFanObj = new vertexFan();
          vertexFanObj.setupVertex(j, -j);
myLL2.add(vertexFanObj);
for (int i = 0; i < 10; i++) {
myLLLength = myLL2[ i].size();
for (int j=0; j<myLLLength; j++) {
vertexFanObj2 = myLL2[ i].get(j);
System.out.println(vertexFanObj.vertex1+" "+vertexFanObj.vertex2);
class vertexFan {
int vertex1, vertex2;
void setupVertex(int vertexA, int vertexB) {
vertex1=vertexA;
vertex2=vertexB;
I 've got lost! Please kindly help you! Many thanks in advance!

for (int i = 0; i < 10; i++) {
myLL2[ i] = new LinkedList();
for (int j=0; j < 5; j++) {
vertexFanObj = new vertexFan();
vertexFanObj.setupVertex(j, -j);
myLL2.add(vertexFanObj);
for (int i = 0; i < 10; i++) {
myLLLength = myLL2[ i].size();
for (int j=0; j<myLLLength; j++) {
vertexFanObj2 = myLL2[ i].get(j);
System.out.println(vertexFanObj.vertex1+" "+vertexFanObj.vertex2);
} Its a scope issue.
You define vertexFanObj in a for loop. then try to access it from outside that for loop. (in another for loop)
for (int i = 0; i < 10; i++) {
myLL2[ i] = new LinkedList();
vertexFanObj = new vertexFan(); //I MOVED THIS LINE
for (int j=0; j < 5; j++) {
vertexFanObj.setupVertex(j, -j);
myLL2.add(vertexFanObj);
for (int i = 0; i < 10; i++) {
myLLLength = myLL2[ i].size();
for (int j=0; j<myLLLength; j++) {
vertexFanObj2 = myLL2[ i].get(j);
System.out.println(vertexFanObj.vertex1+" "+vertexFanObj.vertex2);
} should work properly...

Similar Messages

  • Array of cfc object help

    I just picked up coldfusion about a month ago, so my
    coldfusion lingo sucks. I have been programming in C++ for over 5
    years now and will be using a lot of C++ terminology to help avoid
    any confusion. I am writing a cfc function that preforms web
    servicing. This function needs to return an object/class that is
    defined in another coldfusion function. I can do this without a
    problem if I only need to return one instance of this object.
    However, I cannot seem to return an array of this object (I need to
    return multiple instances of this object, kind of like a query, but
    for programming purposes it needs to stay as an object).
    It seems that the webservicing function hates my return type.
    If I try to make an array of the object, it does not like array or
    the object as the return type. However, when I take this function
    out of the cfc, and make it a cfm, it gets the array of objects
    just fine. So, I think I am having issues with the return type on
    the <cffunction> tag. So I came up with the idea of creating
    another object which will hold an array of the first object and
    using the second object as the return type. Here is some psuedo
    code of the function I am working on:
    <cffunction name="SelectGames" access="remote"
    returntype="ArrayOfGames" output="false">
    <!-- arguments --->
    <!--- query --->
    <cfobject component = "myArray" name>
    <cfobject component="games" name="test">
    <cfset counter = 0>
    <cfloop query="getevents">
    <cfset counter = counter + 1>
    <cfset test.Game_id = event_id>
    <cfset test.gameDate = eventdate>
    <cfset test.Starttime = starttime>
    <cfset test.Place = place>
    <cfset test.Level = level>
    <cfset test.Sport = sport>
    <cfset test.Gender = division>
    <cfset test.Opponent = opponent_id>
    <cfset test.Type = type>
    <cfset test.Link = spec_name>
    <cfset myArray.gamesArray[counter] = test>
    </cfloop>
    <cfreturn myArray>
    </cffunction>
    It keeps telling me that it does not recognize the return
    type.
    Here are examples of the two objects I am using from the 2
    dif. cfc files:
    <cfcomponent>
    <cfproperty name="gamesArray" type="array">
    </cfcomponent>
    <cfcomponent>
    <cfproperty name="Game_id" type="numeric">
    <cfproperty name="gameDate" type="date">
    <cfproperty name="Starttime" type="string">
    <cfproperty name="Place" type="string">
    <cfproperty name="Level" type="string">
    <cfproperty name="Sport" type="string">
    <cfproperty name="Gender" type="string">
    <cfproperty name="Opponent" type="string">
    <cfproperty name="Type" type="string">
    <cfproperty name="Link" type="string">
    </cfcomponent>
    Feel free to post any questions to clear anything up, I know
    this is confusing and I probably did a poor job of explaining my
    problem. Also, if I throw this code into a cfm and try to make an
    array of games, it works, this is the code I got it to work with:
    <cfset myArray = newArray(1)>
    <cfloop query="getevents">
    <cfset counter = counter + 1>
    <cfset test.Game_id = event_id>
    <cfset test.gameDate = eventdate>
    <cfset test.Starttime = starttime>
    <cfset test.Place = place>
    <cfset test.Level = level>
    <cfset test.Sport = sport>
    <cfset test.Gender = division>
    <cfset test.Opponent = opponent_id>
    <cfset test.Type = type>
    <cfset test.Link = spec_name>
    <cfset myArray[counter] = test>
    </cfloop>
    I guess my problem is I do not know how to specify a type for
    an array.

    The return type of this FUNCTION would be returnType="array".
    No matter
    what kind of data the array contained.
    That's what I get for fast proofing.
    Ian Skinner wrote:
    > I would have to play with your code more if this does
    not clear it up
    > for you, but lets start with this simple concept first.
    >
    > You mentioned "typing the array" several times.
    ColdFusion is typeless,
    > you don't type an array, it is just array. An array of
    strings is the
    > same as an array of integers which is the same as an
    array of objects.
    >
    > So if you had a function something like this.
    >
    > <cffunction returnType="array" ...>
    > <cfset theArray = arrayNew()>
    >
    > <cfloop ...>
    > <cfset arrayAppend(theArray, newObject)>
    > </cfloop>
    >
    > <cfreturn theArray>
    > </cffunction>
    >
    > The return type of this function would be
    returnType="array". No matter what
    > kind of data the array contained.
    >
    > mwiley63 wrote:
    >> I just picked up coldfusion about a month ago, so my
    coldfusion lingo
    >> sucks. I have been programming in C++ for over 5
    years now and will
    >> be using a lot of C++ terminology to help avoid any
    confusion. I am
    >> writing a cfc function that preforms web servicing.
    This function
    >> needs to return an object/class that is defined in
    another coldfusion
    >> function. I can do this without a problem if I only
    need to return
    >> one instance of this object. However, I cannot seem
    to return an
    >> array of this object (I need to return multiple
    instances of this
    >> object, kind of like a query, but for programming
    purposes it needs to
    >> stay as an object).
    >> It seems that the webservicing function hates my
    return type. If I
    >> try to make an array of the object, it does not like
    array or the
    >> object as the return type. However, when I take this
    function out of
    >> the cfc, and make it a cfm, it gets the array of
    objects just fine.
    >> So, I think I am having issues with the return type
    on the
    >> <cffunction> tag. So I came up with the idea
    of creating another
    >> object which will hold an array of the first object
    and using the
    >> second object as the return type. Here is some
    psuedo code of the
    >> function I am working on:
    >>
    >> <cffunction name="SelectGames" access="remote"
    >> returntype="ArrayOfGames" output="false">
    >> <!-- arguments --->
    >> <!--- query --->
    >> <cfobject component = "myArray" name>
    >> <cfobject component="games" name="test">
    >> <cfset counter = 0>
    >> <cfloop query="getevents">
    >> <cfset counter = counter + 1>
    >> <cfset test.Game_id = event_id>
    >> <cfset test.gameDate = eventdate>
    >> <cfset test.Starttime = starttime>
    >> <cfset test.Place = place>
    >> <cfset test.Level = level>
    >> <cfset test.Sport = sport>
    >> <cfset test.Gender = division>
    >> <cfset test.Opponent = opponent_id>
    >> <cfset test.Type = type>
    >> <cfset test.Link = spec_name>
    >> <cfset myArray.gamesArray[counter] = test>
    >> </cfloop>
    >> <cfreturn myArray>
    >> </cffunction>
    >>
    >> It keeps telling me that it does not recognize the
    return type.
    >> Here are examples of the two objects I am using from
    the 2 dif. cfc
    >> files:
    >> <cfcomponent>
    >> <cfproperty name="gamesArray" type="array">
    >> </cfcomponent>
    >> <cfcomponent>
    >> <cfproperty name="Game_id" type="numeric">
    >> <cfproperty name="gameDate" type="date">
    >> <cfproperty name="Starttime" type="string">
    >> <cfproperty name="Place" type="string">
    >> <cfproperty name="Level" type="string">
    >> <cfproperty name="Sport" type="string">
    >> <cfproperty name="Gender" type="string">
    >> <cfproperty name="Opponent" type="string">
    >> <cfproperty name="Type" type="string">
    >> <cfproperty name="Link" type="string">
    >> </cfcomponent>
    >>
    >> Feel free to post any questions to clear anything
    up, I know this is
    >> confusing and I probably did a poor job of
    explaining my problem.
    >> Also, if I throw this code into a cfm and try to
    make an array of
    >> games, it works, this is the code I got it to work
    with:
    >> <cfset myArray = newArray(1)>
    >> <cfloop query="getevents">
    >> <cfset counter = counter + 1>
    >> <cfset test.Game_id = event_id>
    >> <cfset test.gameDate = eventdate>
    >> <cfset test.Starttime = starttime>
    >> <cfset test.Place = place>
    >> <cfset test.Level = level>
    >> <cfset test.Sport = sport>
    >> <cfset test.Gender = division>
    >> <cfset test.Opponent = opponent_id>
    >> <cfset test.Type = type>
    >> <cfset test.Link = spec_name>
    >> <cfset myArray[counter] = test>
    >> </cfloop>
    >>
    >> I guess my problem is I do not know how to specify a
    type for an array.
    >>

  • NullPointerException with an array of LinkedList

    Hello Everybody.
    I'm new to Java and I am trying to use a quite complicated data structure but I am missing something since it does not work.
    Here comes my code:
    import java.util.LinkedList;
    class ObjectToHold {
    public int i;
    ObjectToHold (int j) {
    i=j;
    public class ModifiedArray {
    static final int ARRAY_DIMENSION = 79;
    private LinkedList[] myInternalArray;
    ModifiedArray() {
    LinkedList[] myInternalArray = new LinkedList[ARRAY_DIMENSION];
    for (int i=0;i<ARRAY_DIMENSION;i++) {
    myInternalArray[i] = new LinkedList();
    void insert (int slot, ObjectToHold a) {
    ((LinkedList)myInternalArray[slot]).addLast(a);
    public static void main(String[] args) {
    ModifiedArray myModifiedArray = new ModifiedArray();
    for (int j=0; j<ARRAY_DIMENSION;j++) {
    myModifiedArray.insert(j,new ObjectToHold(j));
    The class ModifiedArray contains a private array of LinkedList objects. I wrote an "insert" method to put objects of type ObjectToHold (which is a very simple one!) into the array.
    While compiling the code, everything works fine.
    On the other hand, when I run the compiled code I get the following run time Exception:
    Java.lang.NullPointerException
    at ModifiedArray.insert ....
    Modified.Array.main ...
    The problem must be in the way I use the reference to myInternalArray.
    I also tried
    myInternalArray[slot].addLast(a);
    instead of
    ((LinkedList)myInternalArray[slot]).addLast(a);
    but I got the same result.
    Can anybody help me or do I have to ask in some other forum?
    Thank you very much
    Tommaso

    You defined myInternalArray as local to the constructor as well as an instance variable.
    Try..
    import java.util.LinkedList;
    class ObjectToHold {
      public int i;
      ObjectToHold (int j) {
        i=j;
    public class ModifiedArray {
      static final int ARRAY_DIMENSION = 79;
      private LinkedList[] myInternalArray;
      ModifiedArray() {
        myInternalArray = new LinkedList[ARRAY_DIMENSION];
        for (int j=0; j<ARRAY_DIMENSION; j++) {
          myInternalArray[j] = new LinkedList();
      void insert (int slot, ObjectToHold a) {
        ((LinkedList)myInternalArray[slot]).addLast(a);
      public static void main(String[] args) {
        ModifiedArray myModifiedArray = new ModifiedArray();
        for (int j=0; j<ARRAY_DIMENSION;j++) {
          myModifiedArray.insert(j,new ObjectToHold(j));
    }

  • Is Array in java are Object?

    is Array in java are Object?
    int a[]=new int[10];
    new will allocate memory. but int is a type not an Class ?
    please help me.......

    An array in Java is an object. Array elements may be primitives or references, depending on the way the array is declared.

  • How to set an array element in an object type of array??

    Hi,
    I have set attribute as follow:
    Color[] colors;
    Color[] colors = new Color[20];
    colors[0] = "Red";
    colors[1] = "blue";I can't compile this code. It said:
    "Incompatible type -found java.lang.String but expected Colors
    Could you tell me how to set an array elements when the array type is an object?

    in your case, the array shouldn't be Color[] but String[] since you re intending to put strings into it
    by the way, you could also use a hashmap to map a string to a color:
    HashMap<String, Color> hm = new HashMap<String, Color>();
    hm.put("Red", Color.RED);
    hm.put("Blue", Color.BLUE);
    etc.

  • How do I get the object help text into my document (report)?

    Post Author: ehskalm
    CA Forum: Desktop Intelligence Reporting
    I want to display the object help text (the "description" field in the object properties in the universe) in my report, but I can not find any function for that? Anyone who knows? BO version is 5.1.

    Post Author: hvanderkolk
    CA Forum: Desktop Intelligence Reporting
    All information about the classes and objects in a universe are stored in the repository database (universe domain). To get that information in your report you need to create a query on the repository database.
    For an overview of all objectnames and descriptions that would be:
    SELECT  WA_UNV_OBJECT.OBJ_NAME,  WA_OBJECT_HELP.OBJ_DATAVALUEFROM  (WA_UNV_OBJECT RIGHT OUTER JOIN WA_OBJECT_HELP ON (WA_OBJECT_HELP.OBJECT_ID=WA_UNV_OBJECT.OBJECT_ID  AND  WA_OBJECT_HELP.UNIVERSE_ID=WA_UNV_OBJECT.UNIVERSE_ID) ) 
    Note: this if from BO6.5 using SQL server 2000 for the repository database.

  • I need abap object help file.helpful link

    i need abap object help file.helpful link

    Hi
    Go through the below links,
    For Materials:
    1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291
    2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
    3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
    4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
    5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
    6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
    7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
    8) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
    OO ABAP links:
    1) http://www.erpgenie.com/sap/abap/OO/index.htm
    2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
    check all the below links
    http://www.sapgenie.com/abap/OO/index.htm
    http://www.geocities.com/victorav15/sapr3/abap_ood.html
    http://www.brabandt.de/html/abap_oo.html
    Check this cool weblog:
    /people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
    /people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm
    http://www.sapgenie.com/abap/OO/
    http://www.sapgenie.com/abap/OO/index.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
    http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
    http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
    http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
    http://www.allsaplinks.com/
    http://www.sap-img.com/
    http://www.sapgenie.com/
    http://help.sap.com
    http://www.sapgenie.com/abap/OO/
    http://www.sapgenie.com/abap/OO/index.htm
    http://www.sapgenie.com/abap/controls/index.htm
    http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
    http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
    http://www.sapgenie.com/abap/OO/index.htm
    http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
    http://www.sapgenie.com/abap/OO/
    these links
    http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
    For funtion module to class
    http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm
    for classes
    http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm
    for methods
    http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
    for inheritance
    http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm
    for interfaces
    http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
    Check these links.
    http://www.henrikfrank.dk/abapuk.html
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/abap%20objects/abap%20code%20sample%20to%20learn%20basic%20concept%20of%20object-oriented%20programming.doc
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/alv%20grid/abap%20code%20sample%20to%20display%20data%20in%20alv%20grid%20using%20object%20oriented%20programming.doc

  • Please tell me how I can set an array field to an object?

    Hi,
    Please tell me how I can set the plID (an array field) to an object? This result is for one Agent object. Suppose the Agent object only has these two fields.
    If a sql query result is something like this (which is one object).
    agent_last PLID
    smith      5
    smith               6
    smith               7
    Agent agent = new Agent();
    StringBuffer sql = new StringBuffer();
    int count = getPLNo(agentID);// # of the query result
    try {
    SQL tsql = new SQL();
    Connection conn = tsql.getConnection();
    sql.append("SELECT agent_last, b.PLID ");
    sql.append("FROM Agent a, PL b ");
    sql.append("where a.agent_id = b.agent_id ");
    sql.append("and a.agent_id = ? ");
    PreparedStatement st = conn.prepareStatement(sql.toString());
    st.setInt(1, agentID);
    ResultSet rs = st.executeQuery();
    while (rs.next()) {
    agent.setAgentID(agentID);
    agent.setAgentLast(rs.getString(1));
    for ( int i = 0 ; i < count; i++ ) {               //how to do it?
    agent.setPrivateLabelID(new int[] {rs.getInt(2)});//how to do it?
    st.close();
    rs.close();
    tsql.close();
    } catch (SQLException e) {
    System.out.println("SQL: " + e.getMessage());
    throw new Exception(e.getMessage());
    } catch (Exception e) {
    System.out.println("Except: " + e.getMessage());
    throw new Exception(e.getMessage());
    return agent;
    }

    If that's not what you're looking for, then you get
    what you pay for. :-)Hi fmeyer75,
    Thank you very much for your input. That's exactly what I was looking for and it works!!!!
    For anyone who has similar issue, I changed the code a little to make it work with my existing ones. I never splited queries before, so please tell me if there's a better way to handle it.
    I keep the first half part and changed a little for the second half. Below is what I use now
    sql.setLength(0);
    sql.append("SELECT PLID ");
    sql.append("FROM PL ");
    sql.append("where agent_id = ? ");
    List list = new ArrayList();
    PreparedStatement st2 = conn.prepareStatement(sql.toString());
    st2.setInt(1, agentID);
    ResultSet rs2 = st2.executeQuery();
    while (rs2.next()) {
                 list.add(new Integer(rs2.getInt(1)));
    agent.setPrivateLabelID(new int[list.size()]) ;
    for ( int i = 0 ; i < list.size(); i++ ) {
    agent.getPrivateLabelID() = ((Integer)
    list.get(i)).intValue() ;
    st.close();
    rs.close();
    st2.close();
    rs2.close();

  • Modifying an element in an array of objects - HELP!

    Hello - I would appreciate any help on this project I am working on for my beginning Java class.
    One of the requirements of my project are to update a string that I have already populated with a new balance, through an update balance method. I'm confused on how to bring the element (string) back from my array so that I can repopulate the name, and phone so that I don't loose that information when updating the balance. I think it should be done in the AcctMaint class. Below is a copy of my code. I have a lot of garbage in there for testing and have not completed all of the requirements, as you will see. Don't laugh to much - I'm new at this! Thank you, JB
    //     Author: JB
    // Bank.java
    //     Purpose:     To create a customer account, make a deposit, make a withdrawl,
    //                         Accure interest on all accounts when the method is invoked.
    import javax.swing.JOptionPane;
    public class Bank
    // Creates an accout object. Adds, deposits, withdrawls. Prints
    // reports on the bank customers
    public static void main (String[] args)
    Customer account = new Customer ();
              String name, phone, numStr;
              double deposit;
              int option, acctnum;
              // Display a menu through a dialog box
              numStr = JOptionPane.showInputDialog ( "MAIN MENU" + "\n" + "-----------------" + "\n" +
              "Create an account: 1" + "\n" + "Make a deposit: 2" + "\n" +
              "Make a withdrawl: 3" + "\n" + "Search for a customer: 4" + "\n" +
              "Customer report: 5" + "\n" + "Accru interest on accounts: 6");
              option = Integer.parseInt(numStr);
              if (option == 1)
                        numStr = JOptionPane.showInputDialog ("Enter a customer last name");
                        name = (numStr);
                        System.out.println (name);
                        numStr = JOptionPane.showInputDialog ("Enter a 10 digit phone number");
                        phone = (numStr);
                        System.out.println (phone);
                        numStr = JOptionPane.showInputDialog ("Enter your deposit");
                        deposit = Double.parseDouble(numStr);
                        System.out.println (deposit);
                        account.addAcct (0, name, phone, deposit, 0);
    // Populate with data for testing
    //                    account.addAcct (0,"George Bush", "3034727812", 140954.95, 0);
    //                    account.addAcct (0,"Hillary Clinton", "7206666666", 0.01, 0);
    //                    account.addAcct (0,"Barb Swayer", "3034724567", 17.95, 0);
    //                    account.addAcct (0,"George Bush", "3034727812", 140954.95, 0);
              if (option == 2)
                        // Get account information
                        account.addAcct (0,"Carol Lund", "3034716278", 124500.98, 0);
                        account.addAcct (0,"George Bush", "7204724415", 0.01, 0);
                        numStr = JOptionPane.showInputDialog ("Enter a customer account");
                        acctnum = Integer.parseInt(numStr);
                        System.out.println(acctnum);
                        numStr = JOptionPane.showInputDialog ("Enter your deposit");
                        deposit = Double.parseDouble(numStr);
                        System.out.println (deposit);
              account.updAcct (acctnum, "Testing Update", "4544444444", 50.95, deposit);
    // List the accounts
    System.out.println (account);
    // Author: JB
    // Customer.java
    // Purpose: Store the account number (using index for account number), name, phone and balance
    import javax.swing.JOptionPane;
    import java.text.NumberFormat;
    import java.util.*;
    public class Customer
    private AcctMaint[] accounts;
    private int count, answer;
    // Creates an initially empty accounts.
    public Customer ()
              int Array_Size = 30;
    accounts = new AcctMaint[Array_Size];
    count = 0;
    // Adds a AcctMaint to the accounts
    public void addAcct (int account, String name, String phone, double balance, double trans)
    accounts[count] = new AcctMaint (account, name, phone, balance, trans);
    count++;
    // Modifies account so that it increases the balance with a deposit
    // accounts if necessary.
    public void updAcct (int account, String name, String phone, double balance, double trans)
    accounts[account] = new AcctMaint (account, name, phone, balance, trans);
              System.out.println ("The customer you will be updating is: " + accounts[account]);
    // Returns a report describing the AcctMaint accounts.
    public String toString()
    NumberFormat fmt = NumberFormat.getCurrencyInstance();
    String report = "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n";
    report += "L&L Accounts\n\n";
    report += "Number Accounts: " + count + "\n";
    report += "\n\nAccount List:\n\n";
    for (int cd = 0; cd < count; cd++)
    report += accounts[cd].toString() + "\n";
    return report;
    // Author: JB
    // AcctMaint.java
    import java.text.NumberFormat;
    public class AcctMaint
    private String name, phone;
    private double balance;
    // Creates a new Account with the specified information.
    public AcctMaint (int Acct, String Cname, String Pnumber, double Abalance, double trans)
         name = Cname;
         phone = Pnumber;
              balance = Abalance + trans;
    // I want to get the string and replace it with the new balance
    //     and old information prior to updating array.
    // Returns a description of this account.
    public String toString()
    NumberFormat fmt = NumberFormat.getCurrencyInstance();
    String description;
    description = fmt.format(balance) + "\t";
    description += name + "\t" + phone;
    return description;
    Thank you again in advance.

    toString() is supposed to do nothing more than return a string representation of an object. If you call toString() in order to assign its return value to a temp variable prior to updating the state of the object, then this satisfies your "capture and store the data". But your original post was concerned with updating an object's fields. This should generally only be accomplished by get/set sorts of methods. But of course, the update method could be a wrapper around the set method, with the additional call to toString() prior to setting the fields, so that you can return the pre-update object data or use it in later calculations or whatever, and also update your fields, all in one method.

  • Need help getting information out of array and into text/object files

    Im having alot of trouble with this i have the classes for the array, text reader and writer, and object reader and writer mostly done. I originally had a getInfo method in my object and text classes to input the data needed, but that wasnt how the instructor wanted. So my question is how do i take the infomation in the array in class studentarray and send that information to the text and object classes? I have looked online for an example and cant seem to find one that looks like it would work. I am pretty sure what i need will be put in the class StudentArray
    here is requirements i havent figured out how to implement
    - read student records from a �text� file
    - write student records into a �text� file (new data after sorting)
    - read student records from an �object� file
    - write student records into an �object� file (new data after sorting)
    I have sorting methods below in StudentArray just didnt post them
    public class StudentArray {
    private static Scanner input = new Scanner(System.in);
    private static student sArray[] = new student[5];
    public static void insert() throws NegativeIDException
    for(int i = 0; i < 5; i++)
    System.out.println("Please enter firstname:");
    String Fname = input.next();
    System.out.println("Please enter lastname:");
    String Lname = input.next();
    System.out.println("Please enter id:");
    int Id = 0;
    try
    Id = input.nextInt();
    NegativeIDException nide = new NegativeIDException("No negative number for id.");
    if(Id < 0)
    throw nide;
    scanner.nextLine();
    System.out.println("you must enter a positive number try again");
    catch(InputMismatchException ime)
    System.err.printf("\nException: %s\n", ime);
    scanner.nextLine();
    System.out.println("you must enter an integer try again");
    System.out.println("Please enter year admitted:");
    int Admitted = 0;
    try
    Admitted = input.nextInt();
    NegativeIDException nide = new NegativeIDException("No negative number for id.");
    if(Admitted < 0)
    throw nide;
    scanner.nextLine();
    System.out.println("you must enter an integer try again");
    catch(InputMismatchException ime)
    System.err.printf("\nException: %s\n", ime);
    scanner.nextLine();
    System.out.println("you must enter an integer try again");
    System.out.println("Please enter Gpa:");
    double Gpa = input.nextDouble();
    int t = 0;
              int q = 0;
              System.out.println("Please select your track");
                   System.out.println("1 for doctoral student");
                   System.out.println("2 for graduate student");
                   System.out.println("3 for major student");
                   System.out.println("4 for minor student");
                   t = input.nextInt();
                   if (t == 1)
                             System.out.println( "Please select your doctoral topic");
                             System.out.println("1 for Video Games");     
                             System.out.println("2 for CPU History");     
                             System.out.println("3 for Other");     
                             int c = input.nextInt();                         
                             String diss = "";
                             if (c == 1)
                                  diss = "Video Games";     
                             else if (c == 2)
                                  diss = "CPU History";
                             else if (c == 3)
                                  diss = "Other";
                             sArray[i] = new CSDoctStudent(Fname, Lname, Id, Admitted, Gpa, diss);
                             q++;                              
                        else if (t == 2)
                        System.out.println( "Please enter the number for your graduate course");
                        System.out.println("1 for Software Engineering");     
                        System.out.println("2 for Theory");     
                        System.out.println("3 for Other");     
                        int b = input.nextInt();
                        String Theory = "";
                        if (b == 1)
                             Theory = "Software Engineering";     
                        else if (b == 2)
                             Theory = "Theory";
                        else if (b == 3)
                             Theory = "Other";
                        sArray[i] = new CsGradStudent(Fname, Lname, Id, Admitted, Gpa, Theory);
                   q++;     
                        else if (t == 3)
                             System.out.println( "Please enter the number for your major course");
                             System.out.println("1 for Hardware");     
                             System.out.println("2 for IS");     
                             System.out.println("3 for Theory");     
                             int m = input.nextInt();
                             String track = "";
                             if (m == 1)
                             track = "Hardware";
                        else if (m == 2)
                             track = "IS";
                        else if (m == 3)
                             track = "Theory";
                             sArray[i] = new CSMajorStudent(Fname, Lname, Id, Admitted, Gpa, track);
                             q++;     
                   else if ( t == 4)
                             System.out.println( "Please enter the number for your minor course");
                             System.out.println("1 for Computer Application");     
                             System.out.println("2 for Multimedia");     
                             System.out.println("3 for Web Technology");
                             int d = input.nextInt();
                             String Hardware = "";
                             if (d == 1)
                                  Hardware = "Computer Application";     
                             else if (d == 2)
                                  Hardware = "Multimedia";
                             else if (d == 3)
                                  Hardware = "Web Technology";
                             sArray[i] = new CSMinorStudent(Fname, Lname, Id, Admitted, Gpa, Hardware);
                             q++;     
                   else;
    sArray= new student(Fname,Lname,Id,Admitted, Gpa);
    //trying to write it to a text file with this
    import java.io.PrintWriter;
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    public class TStream {
    private Scanner input = null;
    private PrintWriter output = null;
    private student [] sArray = new student[5];
    public TStream()
    public void write()
    try
    output = new PrintWriter("tdatabase.txt");
    for(int i = 0; i < 5; i++)
    output.print(sArray[i].getFname() + "\t");
    output.print(sArray[i].getLname() + "\t");
    output.print(sArray[i].getId() + "\t");
    output.print(sArray[i].getAdmitted() + "\t");
    output.print(sArray[i].getGpa() + "\t");
    output.println();
    output.close();
    catch(FileNotFoundException fnfe)
    System.err.printf("\nException: %s\n", fnfe);
    System.out.println("Can not open this file.\n");
    public void read()
    try
    input = new Scanner(new File("tdatabase.txt"));
    for(int i = 0; i < 5; i++)
    String Fname = input.next();
    String Lname = input.next();
    int Id = input.nextInt();
    int Admitted = input.nextInt();
    double Gpa = input.nextDouble();
    sArray[i] = new student(Fname,Lname,Id,Admitted,Gpa);
    input.close();
    catch(FileNotFoundException fnfe)
    System.err.printf("\nException: %s\n", fnfe);
    System.out.println("Can not open this file.\n");

    Use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Array access in an object

    I've encountered another problem.
    The following code does not mention that I have a MovieClip
    in the Library set up with its class as my_class. I drag it onto
    the stage and name it my_object. When I try to use the my_array
    property it does not work.
    The class includes a boolean property that works fine, so I
    concluded that my arrays must be discombobulated. I also tested a
    string property and it works.
    Plz help?

    Omg. I fiddled with this and apperently did just that. That
    would explain why it's doing soemthing now,
    It's still not working properly. I have three objects, and I
    set the first spot in each to three different things, but when I
    trace them all of the array values are set to the same value as the
    last object. No code modifies them after they are set. I checked.
    It's sure behaving like a static property.

  • Display byte array image or ole object in Section through dynamic code?

    To Start I am a Complete Newbe to Crystal Reports. I have taken over a project originally written in VS2003 asp.net using SQL Server 2005 and older version of Crytal Reports. I have moved project to VS2010 and Cryatal Reports 10 still using SQL Server 2005. Have multiple reports (14 to be exact) that display data currently being pulled from database suing a dataset, each report has from 4 to 14 Sections. I have modified database table with two new fields. Field1 contains string data with full path to a scanned document (pdf or jpeg). Field2 holds a byte array of the actual image of the scanned document. I have tested the database and it does infact contain the byte array and can display the image via VB.net code. I can make the report display the scanned image using ole object.
    Now my real question: I need to add a new Section and it should display either the byte array of the scanned image or the actual scanned image (pdf or jpeg) . How can I have it do either of these options via code dynamicly while application is running?

    First; only CRVS2010 is supported on VS2010. You can download CRVS2010 from here;
    SAP Crystal Reports, developer version for Microsoft Visual Studio: Updates & Runtime Downloads
    Developer Help files are here:
    Report Application Server .NET API Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/xi4_rassdk_net_api_en.zip
    Report Application Server .NET SDK Developer Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/xi4_rassdk_net_dg_en.zip
    SAP Crystal Reports .NET API Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_api_2010_en.zip
    SAP Crystal Reports .NET SDK Developer Guide http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet_dg_2010_en.zip
    To add the images, you have a number of options re. how to. You even have two SDKs that y ou can use (RAS and CR).
    Perhaps the best place to start is with KB [1296803 - How to add an image to a report using the Crystal Reports .NET InProc RAS SDK|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233393336333833303333%7D.do]. The KB describes how to add images to a report using the InProc RAS SDK, but also references other KBs that use CR SDK.
    Also, don't forget to use the search box in the top right corner of this web page.
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup
    Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

  • Multidimensional array in jquery class/object

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

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

  • How do I get an array of LinkedLists?

    I need an array of liked lists
    I tryed the code:
    LinkedList buckets[] = new LinkedList[radix];But that generated an unchecked warning when I tried to put an Integer into it.
    I changed it to:
    LinkedList<Integer> buckets[] = new LinkedList<Integer>[radix];But that generated a "generic array creation" error.
    is it possible to to get an array of lists without warnings?

    It is possible to use generic arrays (simple ones)
    e.g.
    import java.util.List;
    public class Test
       public static void main(String[] args)
          String[] elements = new String[]{"Happy","Go","Lucky"};
          String middleElement = middleElement(elements);
          System.out.println(middleElement);
       public static <T> T middleElement(T[] elements)
          return elements[elements.length/2];
    }However you cannot (should not) create generic arrays with bounded parameters.
    Lets say that we have somehow create a generic array:
    List<String>[] lists = ...
    Then since lists is an array we can assign it to Object[]
    Object[] objArray = lists;
    and now we can put any list in the array.
    objArray[0] = new ArrayList<Rectangle>();
    Even though this should not happen, the runtime has no way to check aginst it and so no ArrayStoreException is thrown.
    You are however free to:
    List<?>[] lists = new List<?>[5];
    which implies its an array of any type of List.

  • Array Copy for Any Objects

    Hi all,
    I wrote a function which is used to concat two Arrays. HOwever, I need to specifiy the data type in the function, it's not OO and absolutely not dynamic, how can I improve it ?
        public static Object concatDualArray(Object[] A, Object[] B) {
            StandingData[] C= new StandingData[A.length+B.length];
            System.arraycopy(A, 0, C, 0, A.length);
            System.arraycopy(B, 0, C, A.length, B.length);
            return C;
         } I summon that function from my core function, which is
            StandingData[] trancheStatusListData = (StandingData[])
                    TrancheUtility.concatDualArray((Object[])trancheApprovedStatusListData, (Object[])trancheApprovalStatusListData);Is there any reflection method can let my function looks more OO ?
    Thanks for helping me
    Transistor

    Personally I wouldn't go for the array approach in the first place, because
    their type can not be parameterized; e.g. the following is simply not
    possible, no matter how cute it looks:public static<T> T[] concatDualArray(T[] A, T[] B) {
       T[] C= new T[A.length+B.length];
       System.arraycopy(A, 0, C, 0, A.length);
       System.arraycopy(B, 0, C, A.length, B.length);
       return C;
    } Arrays are very non-OO; why not stick to a List<T> instead?
    kind regards,
    Jos

Maybe you are looking for

  • S video output on windows 7

    Hi All, i have HP Pavilion dv5131eu. i have upgraded to windows 7. i have connected to s video cable to the appropriate s video output. now i try to change display to s video and i cannot define it seems that windows 7 does not recognize this output.

  • Error while using Custom File Module..

    Hi Experts, I am trying to conver Excel file to xml file using XI , but i am getting this error in communication channel monitoring, error : com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at co

  • RE: (forte-users) User-visible service object

    This solution will cause network traffic for all method calls on the environment visible SO. This overhead is not incurred when calling methods on a user visible SO in the same partition. Depending on the frequency of calls and the volume of data bei

  • How can i print a color swatch chart of photoshop swatches? [was:jasrhodes]

    how can i print a color swatch chart of photoshop swatches?

  • Pooled data sources

    I've defined a pooled data-source, with an inactivity-timeout="30", min-connections="2" and max-connection="5". I've monitor database connections and when maximum number of connections is reached (5), it never decreases, even past a lot of time (more