Using Classes within Vector

ok,
I writing a bank program where a user types in a string which is then broken into tokens. The tokens are separated using .nextToken( ) and the first token is used to determine what command the user wants to perform.
My problem is that I am trying to place a class that Ive created within the vector and I cant seem to be able to get the tokens into the right place or retrieve them when they are needed.
Here is what I have so far, ps I am very new to java.
Project3Functions func = new Project3Functions();
Vector vect = new Vector();
do
String firstLine = func.getLineInput();
StringTokenizer tok = new StringTokenizer(firstLine," ");
String hold = tok.nextToken();
if(hold.equals("newAccount"))
int index = Integer.parseInt(tok.nextToken());
vect.setSize(index);
vect.add(index, new Account());
vect.add(index, Account.firstname = tok.nextToken());
vect.add(index, Account.lastname = tok.nextToken());
System.out.println("a new account was created");
public class Account
static String firstname = "";
static String lastname = "";
I am trying to create a new Account in the position <index> within the vector but I dont think Im referencing firstname and lastname correctly. Also how would I get firstname and lastname out of the vector to print them on the screen?
Please someone help me.

Don't use static fields in Account - that means that they are shared by all instances. Try something like:
if(hold.equals("newAccount"))
  int index = Integer.parseInt(tok.nextToken());
  vect.setSize(index); // be careful! if index < size, then you will lose elements
  Account acct = new Account();
  acct.firstname = tok.nextToken();
  acct.lastname = tok.nextToken();
  vect.add(index, acct);
  System.out.println("a new account was created");
public class Account
String firstname = "";  //consider using get and set methods
String lastname = "";
}To get the data out,Account acct = (Account) vect.get(index);
System.out.println("firstname = " + acct.firstname + ", lastname = " + acct.lastname);

Similar Messages

  • How to use class within another class?

    Hi,
    I have written a couple of beans, and I have classified them all as part of a "beans" package. All class files are in the same folder. One of the beans in called "ProcessTextBean.class" and it contians a method "validate_email" which validates a supplied email address, I want to call that method from another bean. I think the following line should work but compiler returns an error (Cannot resolve symbol with an arrow underneath "ProcessTextBean"):
    boolean result = beans.ProcessTextBean.validate_email("[email protected]");
    Any ideas what I'm doing wrong? Thanks.
    Junaid.

    beans.ProcessTextBean
    Hihi..
    is you validate_email a static method ?
    if not i dun think you can do it.
    you can try the followingf:
    ProcessTextBean ptb = new ProcessTextBean();
    ............. = ptb.validate_email(emailAdd);
    or
    .................... = new ProcessTextBean().validate_email(emailAdd)
    sorry...i may be wrong.
    its a long time since i touch such a wonderful language such as Java..
    now my org using VBA..:(

  • How to import .jar files in order to use the classes within this file

    hello guys,
    I'm just wondering how can i import .jar files in order to uses the classes within this file.
    let's take an example:
    i have a folder in which I have many .jar files which contain classes to be called. the full path of this folder is set in the Classpath inside the enviroment variables.
    so does anyone have any idea how can i import these .jar files so i can use the classes?
    thank you.

    Hi,
    My problem is that: I created a Serializable class in a project. And I added this project (first project) to another project (second project). First project is appearing in the second project' s Libraries folder. No problem. I want to create a jar file from second project. i.e. I want to Build second project (I use NetBeans IDE). I am using Build Main Project tab under Run. It is falling out. I am finding it second project' s jar file under its folder. I am clicking on it. But it is NOT WORKING. Do you know WHY. Could you help me please?
    Thanks,

  • Triggering Java class within wls using Autosys

    Is it possible to trigger a Java class within the weblogic server externally using an utility like Autosys ?

    Dont know autosys that well but I would guess you would have to invoke java
    and run a starter class.
    There is a good product out there called Flux which is an all java based
    scheduling system that has some great scheduling features and is made
    to trigger either Session Beans, Add entrys to JMS Queues/Topic or
    fire a java class when a scheduled event is fired.
    try
    www.simscomputing.com
    Anil wrote:
    Is it possible to trigger a Java class within the weblogic server externally using an utility like Autosys ?

  • Java Inner classes within the Threading paradigm

    Hi all.
    Im familiar with static nested classes, method local classes, inner classes and anonymous classes.
    But what I am a little perplexed by, is when exactly to use inner classes or static nested classes? (forgetting anonymous classes and method local classes).
    I read this article (http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html) and the first point makes for a good argument, but why nest the class? Why not define it as an external class?
    Also you typically find nested classes within the Threading paradigm, but why?
    I typically would create a top level class (non nested) that would implement the Runnable interface, override run() and then
    use this class when constructing a new Thread.
    Any clarification would be greatly received.
    Thanks and Happy Friday.

    Boeing-737 wrote:
    I read this article (http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html) and the first point makes for a good argument, but why nest the class? Why not define it as an external class?
    I was going to provide some reasons, but when I read the article I found they were already there. Following the DRY principle I'm going to let the article speak for itself.
    Also you typically find nested classes within the Threading paradigm, but why?No, I don't. If that's where you typically find them then you haven't had a varied experience.
    I typically would create a top level class (non nested) that would implement the Runnable interface, override run() and then
    use this class when constructing a new Thread.So carry on doing that, if it works for you.

  • Using variables within GETurl

    Having issues with getting a simple script working...
    I've created a 'flashvars' tag in my embed code (aid=test), which I simply wish to add to the end a GetUrl statement, contained in within a button (which is on the first level of the flash movie). This is the code I've added to the button...
    on (release) {
        getURL("http://www.platinumselect.com?id="+aid);
    But this doesnt seem to work!? Is there anything else I need to do?
    Thanks in advance! (p.s. using actionscript 2.0)

    Where are the 3 places?? I've got it in two at the minute.
    Date: Tue, 10 Nov 2009 07:53:55 -0700
    From: [email protected]
    To: [email protected]
    Subject: Using variables within GETurl
    in as2, there is no LoaderInfo class and you don't need to do anything in flash to parse the flashvars.
    but, as i mentioned in a duplicate post, you do need to define your flashvars in 3 places in your embedding html file.  failure to do that is the most common reason for a problem with flashvars.
    >

  • Standard SAP Reporting Using Classes and Characterstics

    Hi Experts,
    I am currently interested in if there are any options to using classes and characteristics within standard reporting in SAP ECC.  I know some reports have the selection critiera and allow for other fields to be added to reports.  Does anyone know the reports that use classes and characteristics or have the ability to use them.  Any help is appreciated.
    Regards,

    Consultant 01,
    I am not sure of the specifics of your question.  The reporting approach depends on the objective of the reports and the business requirements.  In general, transaction MC03 can be use to report via classification characteristics.  This key figure reporting option covers many classifying attributes.
    If you want to report using batch classification and characteristic values, BMBC offers options for reporting on batches.  In this case you may use the classification tab of BMBC to enter the batch class for "search with batch class" and/or "search with selection class".  The latter allows you to view and/or narrow your search by characteristic values.
    I hope that this helps.
    Regards,
    Wayne

  • ALV Reports using Class Methods

    Hi Experts,
    How can we generate ALV report using class and in that How can we define SLIS_EVENTS.
    Can I provide all the that functionality the way I used to by calling FM
    SLIS_ALV_REUSE_LIST_DISPLAY  ?
    - Like Header comment, event, data grouping , sort etc.
    You may please send any url or document or any example.
    Thanks in advance.
    Regards,
    Tushar Choksi

    Hi,
    The ALV object Grid methods allow the same functionality as ALV grid report function modules but are displayed within
    a screen (dialog program). SAP has provided a suit of programs which demonstrate how to For examples see standard SAP
    programs as detailed below:
    BCALV_EDIT_01 This report illustrates the simplest case of using an editable/noneditable ALV Grid Control.
    BCALV_EDIT_02 This report illustrates how to set chosen cells of an ALV Grid Control editable.
    BCALV_EDIT_03 In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.
    The report checks the input value(s) semantically and provides protocol messages in case of error
    BCALV_EDIT_04 This report illustrates how to add and remove lines to a table using the ALV Grid Control and how to
    implement the saving of the new data.
    BCALV_EDIT_05 This example shows how to use checkboxes within an ALV Grid Control. You learn:
    (1) how to define a column for editable checkboxes for an attribute of your list
    (2) how to evaluate the checked checkboxes
    (3) how to switch between editable and non-editable checkboxes
    BCALV_EDIT_06 This example shows how to define a dropdown listbox for all cells of one column in an editable ALV
    Grid Control.
    BCALV_EDIT_07 This example shows how to define dropdown listboxes for particular cells of your output table.
    BCALV_EDIT_08 This report implements an ALV Grid Control with an application specific F4 help. The following aspects
    are dealt with:
    (1) how to replace the standard f4 help
    (2) how to pass the selected value to the ALV Grid Control
    (3) how to build an f4 help, whose value range depend on a value of another cell.
    some links.
    www.sapgenie.com
    www.abap4u.com
    http://help.sap.com/saphelp_nw2004s/helpdata/en/5e/88d440e14f8431e10000000a1550b0/frameset.htm
    download the PDF from following link.
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
    Regards,
    Satish

  • Use Classes from another webapp

    Hi Everybody!
    I have a webapplication, lets call it "MyWebApp".
    Furthermore I have installed axis in Tomcat.
    Now what I want to do is, create a class, situated within the axis directory, that uses classes that are stored in the "MyWebApp" application.
    Is this possible? If yes, how?
    Thanks in Advance!
    Stef

    No one can help me? ;)

  • Should we use ArrayList or Vector?

    Should we use ArrayList or Vector in web programming environment?
    thanks,

    I used to use ArrayList everywhere since it was a newer class and recommended in books, but use Vector now because it is used in several key environments: Java 1 (Web browsers), Swing and J2ME. In Java2, Vector was retrofitted to use the Collections framework, so Vector implements List.
    Anyway, you should probably deal with only the List interface anyway so whichever you decide will be localized. That way, if Sun suddenly stops supporting Vector, you will only need to make a change in one place.
    List mylist = new Vector();

  • Use classes in JSP without jsp:useBean

    hi
    i want to instantiate my own classes within a jsp.
    the classes are in web-inf/classes/chat/
    there is one main class which is used all over the app, so i use it with the jsp:useBean and scope on application.
    The messages are saved in objects of the class Message. now i want to use this class in my JSP without useBean.
    Is this possible without extra setting the classpath?!
    I get the error because the interpreter searchs in a package from tomcat itself..
    Thanks a lot and rgds
    Ruven

    I think you can use any class in your jsp file without the <jsp:useBean>, this implies that you have to declare your class in the ordinary way i.e
    <% MyClass c = new MyClass() ;
    //other code
    %>
    the important thing is to use the page directive's import attribute i.e include this line in your jsp page
    <%@ page import="mypackage.inner.MyClass" %> the web containers when sees this line will assume that you have the following directory structure in your web application ( /mywebapps/web-inf/classes/mypackage.inner/* )
    I hope this helps
    Regards

  • Creating Instances of class within its definition

    Hi,
    I am a newbie to Java and am doing a course on Java. In one my assignments it asks us to develop the following method for a Class called CraftStock:
    "Define a new helper method void increaseStockCapacity() that creates a
    new expanded array as follows. It should create a temporary instance of
    CraftStock by using its single-argument constructor ? the value of the argument n is determined by the current size of the original craft stock array plus the
    extraCapacity constant. All items in the original array must be copied from the
    original array to the temporary instance of CraftStock. The array reference in the
    original array instance of CraftStock must then be reassigned to the new
    temporary array instance."
    My question is - is this possible - can one create an instance of a class from within its definition? I can't find anyhting on this from the books.
    Any help would be appreciated.
    Thanks
    Dev

    Isn't there a caveat to all this?
    If one creates an instance of a class within its own
    definition, doesn't one face the potential danger of
    attempting to access some part of the object which
    has not yet been constructed?nope. why would it? we're creating a new instance of the class, from scratch. we're not accessing any part of the object, we're creating a new one. the fact that this is being done within the definition of the class is irrelevant. by the time anything comes to call on a static method of the class, the class is initialized already. remember, static methods don't have any dependency on a particular instance
    sorry, that doesn't read very well, does it! what I mean is that the class itself is not the same thing as an instance of that class
    Message was edited by:
    georgemc

  • How to use SelectOneRadio within a DataTable

    Hi,
    I have a requirement to have a radio button for each row in the datatable. It is to enable selecting one row(only one row) from the table and proceed to the next page. The table should look like
    o Name1 address1 city1 state1
    o Name2 address2 city2 state2
    o Name3 address3 city3 state3
    o Name4 address4 city4 state4
    Next>>
    The data structure I have is a collection on objects of type person.
    Class person
    String id;
    String name;
    String address;
    String city;
    String state;
    getters and setters
    I tried to use SelectOneRadio within a Column, but that didnt help. As obvious it treats each rows radio button as a seperate radio group.
    <h:datatable var="person" value="#{personList}>
    <h:column>
    <h:selectOneRadio>
    <f:selectItem itemValue="#{person.id}"/>
    </h:selectOneRadio>
    </h:column>
    <h:column>
    <h:outputText value="#{person.name}"\>
    </h:column>
    </h:datatable>
    I am new to JSF. I searched thru some JSF websites and book, but couldnt find a solution. Can someone help me solve this.
    Thanks in advance
    Rani

    Hi,
    after some time probing into this issue I think none of the many proposed sollutions really solves the underlying problem: Working around the issue becomes much to complicated for JSFs stated design goal of easing development. Certainly for such a common case scenario no workaround should be neccessary, especially given the fact that JSTL is easily able to model this without the need for workarounds!
    In my opinion JSF TagLib implementations should attempt to solve this in a coming version.
    One part of the sollution might be to make <f:selectItem> search it's parent element recursively, i.e. allow the expected container element to be the nearest direct or indirect parent that's suitable. This would allow developers to envelope a <h:dataTable> tag with a <h:selectOneRadio> element. Any <f:selectItem> element inside would therefore be part of a single choice radio button selection, regardless of them being distributed over multiple rows or columns.
    Another part of the sollution might be to allow <h:selectOneRadio> and similar tags to be substitutes for <h:column> tags inside tables. This way a complete column of radio buttons could be used to chose a single value, thereby allowing multiple columns of radio buttons to choose multiple values within the same table.
    Please forward this suggestion for enhancement in kind to the expert group working on the further development of the JSF taglibs. I guess many people besides me already use it as a classical example of complications using JSF during lectures about the tomic, and at least in this case the problem seems completely solvable.
    Kind regards,
    Sascha Baumeister
    software architect, university lecturer and former JCP spec lead JSR086

  • Analyzing classes within a given .jar file

    I want to write some code that will take a given .jar file and look through all of the classes defined within and pick out any classes that implement a couple of given interfaces. I've looked at the URLClassLoader class, but I don't really see how to get it to work. Anyone got any ideas?

    I'm going to guess that your problem is getting a list of classes in the jar file in the first place. To do this, use classes and methods from the java.util.zip package and perhaps also the java.util.jar package.

  • Can I use classes and methods for a maintenance view events?

    Hello experts,
    Instead of perform/form, can I instead use classes and methods, etc for a given maintenance view event, lets say for example I want to use event '01' which is before saving records in the database. Help would be greatly appreciated. Thanks a lot guys!

    Hi viraylab,
    1. The architecture provided by maintenance view
       for using EVENTS and our own code inside it -
       It is provided using FORM/PERFORM
       concept only.
    2. At this stage,we cannot use classes.
    3. However, inside the FORM routine,
       we can write what ever we want.
       We can aswell use any abap code, including
       classes and methods.
      (But this classes and methods won't have any
       effect on the EVENT provided by maintenance view)
    regards,
    amit m.

Maybe you are looking for

  • How do get particular date of total time

    this is our java code     private static PreparedStatement preparedStatement;     private static ResultSet rs;     public static void main(String[] args) throws NamingException, SQLException         int objectId;         int clientId;          DateFo

  • Adobe Premiere Elements 10 on Mac OS 10.7.2 - Hanging and Freezing

    Hello there, While I'm not very knowlegable about video editing software, I do use Premiere Elements 10 to edit videos for YouTube. I recently have been able to record using a device which records in 1080i, 29.97fps and saves as an mp4 file format. I

  • New Problem Viewing Honeymoon Phtos...

    Hello again, Well, as stated in my previous post, it looks as if we were able to salvage about 90% of our honeymoon photos off our memory discs. However, we came across a problem. The way my folders are set up, a thumbnail is viewable as we scroll th

  • Save en send database access 2010

    I have to save an access database and want it in another country when i sent it by mail and they open it, nothing seems to work . how do I do that ?

  • Set trigger property using JDAPI

    Hi. I have a couple of forms I need to modify using JDAPI. Among others I need to set trigger property "Fire in enter query mode" from no to yes. But I just cant find the way how to do this. Any help would be appreciated. Gregor