Last element in array is overwriting the entire array

Hey all,
Im a java student working on a homework assignment. My issue is:
I have created two classes. One called Dependent and one called employee
inside employee i have an array of dependents. The dependents class has methods called getfirstname()
and getlastname();
bascially im doing this.
static Dependent[] Dependents = new Dependent[2];
Dependents[0] = new Dependent("Ryan", "Karr");
Dependents[1] = new Dependent("John", "Doe");
Dependent[0].getFirstName(); // this returns john
Dependent[1].getFirstName(); // this returns john aswell
what am i doing wrong? If i take the static off dependents i get an error.
im sorry if this is sketchy this is my first term taking java.
my source is below
Thank you!
Ryan
public class Employee
     static Dependant[] dependents;                                                       // Dependents Array
     static int numDependents = 0;                                             // Number of Dependents
     public Employee(int pNumDependents)
          dependents = new Dependant[pNumDependents];                         // Instanciate the dependents array
          String dFirstName;                                                       // Dependents First Name
          String dLastName;                                                       // Dependents Last Name
          Scanner input = new Scanner(System.in);                              // New input Scanner
          for(int i = 0; i < dependents.length; i++)
               System.out.println("Dependent #" + (i+1));                    // A little bit of direction for the user
               System.out.println("First Name: ");
               dFirstName = input.nextLine();                                   // Dependents first name from user
               System.out.println("Last Name: ");
               dLastName = input.nextLine();                                   // Dependents last Name from user
               addDependant(dFirstName, dLastName, this);                    // Add dependent call     
     public static void addDependant(String pFirstName, String pLastName, Employee employee)
               // Make a new dependent
               dependents[numDependents] = new Dependant(pFirstName, pLastName, employee);     
               // Number of the dependent we're on plus one
               numDependents++;
}

That was an example i made up. the error is with the code i posted, It doesnt through an error, it runs. However, when i do run it all the information inside is over written by the last value i entered.
the code above was for addDependent which i call in the segment below, which obtains data from the user
          String dFirstName;                                                       // Dependents First Name
          String dLastName;                                                       // Dependents Last Name
          Scanner input = new Scanner(System.in);                              // New input Scanner
          for(int i = 0; i < dependents.length; i++)
               System.out.println("Dependent #" + (i+1));                    // A little bit of direction for the user
               System.out.println("First Name: ");
               dFirstName = input.nextLine();                                   // Dependents first name from user
               System.out.println("Last Name: ");
               dLastName = input.nextLine();                                   // Dependents last Name from user
               addDependant(dFirstName, dLastName, this);                    // Add dependent call     
          }

Similar Messages

  • How to populate one array without running the entire VI

    I'm trying to populate a complex array that I built that reads from a spreadsheet file.  The company I am building it for only has labview run time on the PXI test equipment that I am working with.  I am having to fix the VI On my computer then build an executable and then test it on the machine to see if it runs properly.  It's a very tedious process.  I cannot run the VI on my computer because it requires to have a FLUKE 726 connected in order to run.  So, I was wondering if there is a way to repopulate the array without running the entire VI?
    Your help would be greatly appreciated.

    Create a subVI for reading/processing of the array.  Then you just have to test that subVI as your machine.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can I inverse the Split 1D Array by recombining the splitting array?

    How can I inverse the Split 1D Array by recombining the splitting array? i.e I have two boolean arrays A and B, and I want them in one boolean array: A array elements followed by B elements (NOT Interleaving)
    Thank you
    Solved!
    Go to Solution.

    Thank you Marcus_Körner , GerdW and thoult for your assistance.
    Sorry I am using Labview 2013, so I saved it in ver 2010 format, and I uploaded a photo for the circuit.
    Attachments:
    Packets.vi ‏8 KB
    Untitled.png ‏5 KB

  • Which index values can be sent to "Insert Into Array" without changing the present array ? E.g. index -1 ?

    Which index values can be sent to "Insert Into Array" without changing the present array ? E.g. index -1 ?
    Could not find this info via the "Context Help" window.

    If you have to handle situations where you do not want to insert something in an array, then you can either use a negative index value as you suggested, or put the insert node in a case structure, with the "do not insert" case empty (almost...just crossed by the array wire!..)
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • TMG 2010 Array Brings down the entire internal network

    Ok, so this is a weird as it sounds. 
    We've been working with ISA and TMG since 2004, this is the first time I've seen this kind of behavior. Let me explain the details.
    We implemented 3 TMG 2010 Servers in an Array and 2 EMS Servers on Windows Server 2008 R2. Each TMG Server has 4 NICs (Internal, External, DMZ-Intra-array). At first we wanted to enable them with an F5 Hardware Load Balancer but after weeks of trying to
    make them work together we couldn't (SNAT and routing issues related), so we tried using Windows NLB but had problems with the Multicast configuration using VMWare and after some other battles we decided to first try out just using one TMG Server as the main
    one to try to make it work. The customer we are implementing this is currently using ISA 2006 and they wanted to upgrade to TMG 2010 using basically the same stuff as their ISA had, so we backed up that configuration and imported it into TMG without problems.
    We added the TMG Servers on the EMS configuration and everything replicated just fine.
    Since they already had IPS, Cisco ASAs and Ironports as Proxy they decided to disable NIS, Malware inspection, Flood Mitigation and all those things TMG has for better securing Internet traffic.
    The firewall policy rules are about 100 and they have 3 publishing rules to HTTPS Services. 
    So after making the necessary configuration changes to the TMG infrastructure, we then decided to unplug the ISA Servers, change the TMG servers IP Address to the ISA Server ones and test to see if everything worked just as ISA Server did. However it didn't.
    At first we have issues related to slow internet traffic, after troubleshooting for some time we ended up finding out that the Source IP used by TMG was different that the one ISA was using, even if the same IP was configured in the NIC and the other IPs
    were configured as alternate. We found out after some searching that Windows Server 2008 R2 uses some RFC and manipulates the IP Address on a NIC in a way that 2003 didn't. We found out that we needed to add the other IPs via Netsh int ipv4 add address
    <Interface Name> <ip address> skipassource=true
    After that configuration we got things working fine... for a while, several hours later, servers started losing connectivity, switches stopped responding and the entire network was collapsed! After unplugging the TMG Servers, everything returned back to
    normal.  We though this was a issue related to drivers or something to do with VMWare plataform, so it was decided to reinstall everything on physical servers.
    After some days of reconfiguring again TMG Servers, we made the switch again, unplugged the ISA Servers, configured the TMG with the ISA IP Addresses, did the NETSH thing and then tested out everything and everything worked.
    But again hours later the same behavior appeared once more! Servers and switches stopped responding and the entire network went down once more! Again we unplugged the TMG Servers and everything returned back to normal!
    So here we are, back to square one with no clue on what is causing this behavior on the network. The current physical servers are running HP 3666i 4 multiport 10Gb NICs, we don't know if that has something to do with this. Or the fact the the switch core
    to which the TMG servers are directly connected to is a Nexus 7000 and there is some configuration issues with it against the TMG or something. The TMGs are patched with Service Pack 2 Update Rollup 5.
    We are probably going to open a support case with Microsoft with this issue, but we first wanted to see if anyone else may have had, seen or heard something related to this and has an explanation or ideas on why is this happening.
    I appreciate any replies.
    Thank you all.
    Eduardo Rojas

    Hi, I belive your TMG is virtual and NLB is setup. If so you need to bind the physical swith port with NLB MAK address in multicaste mode. Let's take an example, if your internal NLB physical NIC is connected to swith port 1 and 2 then you need to manually
    bind the NLB MAK to port 1 and 2 like wise for all NLB enabled zone.Read VM ware NLB as they support multicaste in virtual. So do not use unicaste in NLB if it's virtual. All should be okay with the above configuration.

  • How can I, depending on the elemnts of an array, write into the same array

    Hi everyone, to make this a little clearer, consider a 2*2 I8 array, many y objective is the following:
    1) connect the array to the case structure, and depending on a specific case that's value of element of indeces (0,0), write over the same array in this way
    1 0
     2 3 
    for example, note that in (0,0) there's 1, so my decision is to make the array (same array) as:
    0 0
    2 3
    any ideas?
    Thanks.
    T. A.

    toniaz wrote:
    ... should I add the array itself inside the loop or should I add its local variable?
    The array data is in the shift register or wire!
    Any controls or indicators of the array just lets you interface to it via the front panel. Don't use controls or indicators as data storage via local variables, that's not the right way.
    Here's a very simple demo (LV 8.0) that shows one possibility how to do this. See if it makes sense.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    changeArrayElement.vi ‏18 KB

  • I have an array of clusters of 4 numeric indicators and i want to plot 2 of them in a xy graph for the entire array? How can you seperate out 2 of the indicators of each cluster for the entire array

    I have keithley 238 SMU, which when used in sweep mode returns the value in a array of cluster of 4 numeric indicators of which 2 are voltage and current and other two are step size and delay....I want to plot
    I-V curves, how to do that?

    Hello aby
    this could be a possible solution to separate 2 values from an array of 4 elements clusters an create 2 arrays suitable for graphing.
    Hope it helps.
    Alipio
    "Qod natura non dat, Salmantica non praestat"
    Attachments:
    a_solution.vi ‏24 KB

  • How to set the value of an array element (not the complete array) by using a reference?

    My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.
    In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).
    The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
    tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.
    If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.
    Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.
    I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.
    My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done ;-) but I'd still like to know ho
    w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.

    > My situation is that I have an array of clusters on the front panel.
    > Each element is used for a particular test setup, so if the array size
    > is three, it means we have three identical test setups that can be
    > used. The cluster contains two string controls and a button: 'device
    > ID' string, 'start' button and 'status' string.
    >
    > In order to keep the diagrams simple, I would like to use a reference
    > to the array as input into a subvi. This subvi will then modify a
    > particular element in the array (i.e. set the 'status' string).
    >
    It isn't possible to get a reference to a particular element within an
    array. There is only one reference to the one control that represents
    all elements in the array.
    While it may seem better to use references to update
    an element within
    an array, it shouldn't really be necessary, and it can also lead to
    race conditions. If you write to an element that has the
    possibility of the user changing, whether you write with a local, a
    reference, or any other means, there is a race condition between the
    diagram and the user. LV will help with this to a certain extent,
    especially for controls that take awhile to edit like ones that use
    the keyboard. In these cases, if the user has already started entering
    text, it will not be overwritten by the new value unless the key focus
    is taken away from the control first. It is similar when moving a slider
    or other value changes using the mouse. LV will write to the other values,
    but will not rip the slider out of the user's hand.
    To completely avoid race conditions, you can split the array into user
    fields and indicators that are located underneath them. Or, if some
    controls act as both, you can do like Excel. You don't directly type
    into the cell. You choose w
    hich cell to edit, but you modify another
    location. When the edit is completed, it is incorporated into the
    display so that it is never lost.
    Greg McKaskle

  • How do I store the values in the @D array in the below mentioned VI? Only the last row in the Array is populated with values from the image.

    Hello Guys,
    I am trying to build a sinogram from 180 projection images and I am not able to store the summed values into the array as it is moving the values and then populating all the rows except for the last with ZERO.
    Thanks in advance.
    Attachments:
    sinogram.vi ‏53 KB

    Your loop runs only three times, so all you can possibly populate is 3 rows.
    Typically, you would initialize a shift register with the initialized array, then use replace array subset, feeding the modified array back into the shift register. However, in this case you could just autoindex the 1D array at the output tunnel to build the resulting 2D array.
    Sorry, I am not familiar with sinograms. Do you have a link describing the algorithm?
    LabVIEW Champion . Do more with less code and in less time .

  • Quick question how to wrie entire array in one go without loop

    I have the following loop, which goes around store array and write each element to file one at a time, i have been told that i can do this an easy way by writting the entire array at once. Can anybody tell me how to do this?
    int storeSize = store.getCount();
    for (int i = 0; i<storeSize;i++)
    output.writeObject(store.elementAt(i));

    i believe the method is
    Arrays.fill(
    read the api of the Arrays classPerhaps you should read the API, too, before
    offering advice.eerm, i dont need to read the api because i know this method exists:
    static void      fill(Object[] a, Object val)
    Assigns the specified Object reference to
    each element of the specified array of Objects.I'm sorry, you're absolutely right. Original poster, stop serializing objects
    to that ObjectOutputStream, and instead fill an array with multiple
    references to the same value. Whew, that was a close one, eh mates?

  • How can I keep all the previous datas in the same array?

    I have a problem with keeping the previous datas in my array. The problem is when the iteration loop is executed, I have one or two value(s) stored in the array. The second iteration I have either one or two values (depending on the condition) coming out, but it overwrites my previous value. I want to keep all my data in the same array as the loop is executed.PS. I have attached a simple vi along this message. If anyone can help me out with this, I really appreciate for the help.
    Regards,
    Sonny

    If you iterate several times (N > 100) then I would suggest using the Initialize Array outside of the For Loop and then use the Replace Array Subset inside the Loop to populate the array. The reason for this is because the Build Array utility has to locate a new space in memory for the newly concatenated array -- the Replace Array Element utility uses the same memory space.
    If you iterate just a few times with a small array then using the Build Array should be okay.
    Chris_Mitchell
    Product Development Engineer
    Certified LabVIEW Architect

  • Checking entire array for collision? How? AS 2.0

    Hi!
    I am doing a flash game with Actionscript 2.0 and have encountered a problem.
    I have this statement _root.bulletArray = [] that is storing all my movieclips that have been created with attachMovieClip. I was able to store all bullets in the array because when I say for it to trace the array I get the following:
    _level0.bulletCopy39
    _level0.bulletCopy39,_level0.bulletCopy43
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55,_level0.bulletCopy59
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55,_level0.bulletCopy59,_level0.bulletCopy63
    and etc...
    But how do I detect collision with ALL the bullets?
    I have a movieclip that has the instance name: enemy
    I have written the following:
    if(_root.bulletArray.hitTest(_root.enemy))
    trace("hit")
    It dosent work, notihing is traced in the command thing.
    But if I do the follwing:
    if(_root.bulletArray[1].hitTest(_root.enemy))
    trace("hit")
    then it will detect the collision, but only of that bullet, not of the entire array of bullets.
    Any help is highly appreciated! =D
    ----NOTE-----
    I have also tried the followign without sucess:
    if(_root.bulletArray[1,2,3,4,5,6,7,8,9,10].hitTest(_root.enemy))
    trace("hit")

    You need to use a loop to go thru the entire array one element at a time...
    for(i=; i<bulletArray.length; i++){
         if(_root.bulletArray[i].hitTest(_root.enemy))
              trace("hit")

  • Last element in string

    Hello all
    I am having a string like this:
    55.000000; 10.000000; 0.100000; 1.000000; 1.000000; 0.100000; 0.000000; 0.000000; 1.000000; 1.000000; 22.000000; 0.100000; 6144.000000;
    The length of the string is not always same. What i want is to have the last element. i.e in this case  6144
    One way is to get the string length and using string subset to get the last element. But for this, the length must be always constant.
    Is there any other way to get the last element independant of the string length
    thanks
    Nghtcwrlr
    ********************Kudos are alwayzz Welcome !! ******************
    Solved!
    Go to Solution.

    Since you have the extra semicolon at the end, I actually grabbed the second-to-last element of the array after the spreadsheet string to array.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Get last element.png ‏13 KB

  • Promise Pegasus: migrated to larger array, Mac still sees smaller array.

    On my R6 Pegasus, I migrated from a 4x1tb raid 5 (3tb capacity) to a 5x1tb raid 5 (4tb capacity) array. I did this with the Pegasus utility. I did not have to delete my old array, I just used Promise's utility to migrate the raid 5 array from 4 disks to 5 disks. When done i had the Promise utility expand the logical volume from 3tb to 4 tb. The array still shows up on my Mac, but only showing a 3tb size. Disk utility on Mac shows the drive as a 4tb drive, but with only a 3tb partition. I've tried using disk utility to expand the partition to 4tb, but it always reverts to 3tb. I know I could always delete the entire array (I have good backups) and rebuild from scratch, but don't want to go through the hassles if I can help it! Any ideas? Thanks!

    I had foreseen such trouble, so when I received a fresh R6 x 1TB, I decided to experiment a bit. I deleted the factory installed 6-disk RAID5, had a 4-disk RAID5, a single global spare and a single disk partitioned and formatted by the Pegasus Utility as 500 MB. When extending the 500 MB to 1 TB, using the Promise utility, the utility says the logical drive has 1TB capacity.
    As you indicate, Disk Utility cannot expand to the full 1TB logical drive size.
    So part of the answer is 'it is independent of RAID configuration'.
    To save other people the trouble of testing, I decided to consider my options.
    To test if it has to do with the formatting by Pegasus Utility, I deleted the logical drive and made a new logical 500GB drive, this time with the 'format' option OFF. I then partitioned the 500 GB logical drive using Disk Utility and set it to 500 GB. In the Promise utility, I started the Background Activities Migration option and expanded the RAID0 500 GB volume to 1000GB. diskutil list shows
    Unfortunately, Disk Utility still fails to extend the current partition layout from 500 GB to 1 TB. Restarting the subsystem/MacOS did not help.
    Re-partitioning the logical volume in Disk Utility (and thus wiping all data on the partition) DOES work however. So it is "just" MacOS/Disk Utility not being able to expand the already present partition.
    I notice that if you create another logical drive on the remaining space of the disk, it appears as a new partition on a new disk in Disk Utility(screenshot above then shows /dev/disk3/), not as a second partition on the same disk (as would have been the case on an internal disk or USB/FireWire external single disk). This even happens when you create both partitions on the same disk array at the same time.
    Using diskutil I found out that even though Pegasus Utility and Disk Utility both report disk capacity to be 1 TB,
         diskutil resizeVolume disk2s2 limits
    shows
         Current size:  499.7 GB (499656028160 Bytes)
         Minimum size:  5.8 GB (5816856576 Bytes)
         Maximum size:  499.7 GB (499656028160 Bytes)
    The only way one can use the maximum capacity of new disks, seems to remove disk 6 from a 6-disk RAID5 (net capacity 5 TB), copy 1 TB to the now externally attached 1TB disk, swap disk 6 (auto rebuild off) with a 4 TB disk, copy all data to the 4TB disk, swap the remaining 5 disk with 4TB disks, make them RAID0, copy from disk 6 to RAID and then upgrade from RAID0 to RAID5 by adding disk 6 to the RAID. This adds redundancy but does not change the maximum disk size, hence does not require resizing the partition.
    Finally copy the 1TB disk content back to the now 20 TB RAID5.

  • How to find the last element of a byte array

    Dear all,
    I have a byte array with a max lenght of 1024*50 bytes. In that array I store the bytes read from a file. How can I find where the array ends (i.e. which is the last valid element of the byte array)?
    Thank you for your help.
    Best Regards,
    JIM

    I want to send files over TCP connection using BufferedOutputStreams and BufferedInputStreams. The first side (e.g. the client) sends a file (e.g mp3 file or jpeg image) to the server using the code
      public void sendFile(Socket s, String FileName) throws Exception
              BufferedOutputStream out = new BufferedOutputStream(s.getOutputStream());  
              BufferedInputStream in = new BufferedInputStream(new FileInputStream(FileName));
              int len = 0;
              while ( (len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
              in.close();
              out.flush();
            }(The client does not close the BufferedOutputStream out because other files will be sent afterwards)
    Then, the server receives the file using the code:
            public void receiveFile(Socket s, String FileName) throws Exception
              OutputStream out = new BufferedOutputStream(new FileOutputStream(FileName)); 
              InputStream in = new BufferedInputStream(s.getInputStream());
              int len = 0;
              while ( (len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
                break;
              out.flush();
              out.close();
            }(likewise the InputStream in is not closed for the same reasons).
    In order the server to receive the file and stop reading the BufferedInputStream, I will have to make some modifications to this part of the code,
    while ( (len = in.read(buffer)) > 0)so as to know when the whole file has been received.
    Thus, even if I send the length of each file, I will not be able to read it. Could you please recommend me a solution?

Maybe you are looking for