it looks like your code is working just fine to me, its doing exactly what
you wrote it to do.  i suggest reading an introductory java book, the wrox
java2 book is ok.  and this is not the mailing list for these types of
questions.

matt
----- Original Message -----
From: "Rick Roberts" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Thursday, January 10, 2002 3:49 PM
Subject: Vectors? Why does this not work?


> Why does this simple example not work?
> I am using Tomcat 3.3 and JDK 1.3.1_01 and Redhat Linux 7.2
>
> Thanks,
>
> ==============
>
> // SimpleClass.java
> // A Simple Class
> public class SimpleClass extends Object{
>     private static String last_name;
>     private static String first_name;
>     private static String middle_name;
>
>     // Constructor
>     public SimpleClass() {
>         this.last_name = null;
>         this.first_name = null;
>         this.middle_name = null;
>     }
>
>     public void setLastName( String val ) {
>         this.last_name = val;
>     }
>
>     public String getLastName( ) {
>         return this.last_name;
>     }
>
>     public void setFirstName( String val ) {
>         this.first_name = val;
>     }
>
>     public String getFirstName( ) {
>         return this.first_name;
>     }
>
>     public void setMiddleName( String val ) {
>         this.middle_name = val;
>     }
>
>     public String getMiddleName( ) {
>         return this.middle_name;
>     }
>
>     public String getFullName( ) {
>         return this.last_name + (this.first_name == null ? "" : ", " +
> this.first_name) + (this.middle_name == null ? "" : " " +
this.middle_name);
>     }
>
> }// class SimpleClass
> ============
>
>
> // VectorTest.java
> // A Simple Vector Test
> import java.util.*;
>
> import SimpleClass;
>
> class VectorTest{
>
>     public static void main( String args[] ){
>         Vector v = new Vector();
>
>         String firstNames[] = {
>             "George",
>             "John",
>             "Thomas",
>             "James",
>             "James",
>             "John",
>             "Andrew",
>             "Martin",
>             "William",
>             "John",
>             "James",
>             "Zachary",
>             "Millard",
>             "Franklin",
>             "James"
>         };
>
>         String lastNames[] = {
>             "Washington",
>             "Adams",
>             "Jefferson",
>             "Madison",
>             "Monroe",
>             "Adams",
>             "Jackson",
>             "Buren",
>             "Harrison",
>             "Tyler",
>             "Polk",
>             "Taylor",
>             "Filmore",
>             "Pierce",
>             "Buchanan"
>         };
>
>         System.out.println( "\nPut class in Vector." );
>         for( int i=0; i<15; i++ ){
>             SimpleClass inClass = new SimpleClass();
>             inClass.setFirstName( firstNames[i] );
>             inClass.setLastName( lastNames[i] );
>             System.out.println( i + ": " + inClass.getFullName() );
>             v.addElement( inClass );
>         }
>
>         System.out.println( "\n\nRetrieve class from Vector." );
>         for( int i=0; i<15; i++ ){
>             SimpleClass outClass = (SimpleClass)v.elementAt( i );
>             System.out.println( i + ": " + outClass.getFullName() );
>         }
>
>     } //main()
>
> }//class VectorTest
> =============
>
> Here is my output:
>
> [projects]# java VectorTest
>
> Put class in Vector.
> 0: Washington, George
> 1: Adams, John
> 2: Jefferson, Thomas
> 3: Madison, James
> 4: Monroe, James
> 5: Adams, John
> 6: Jackson, Andrew
> 7: Buren, Martin
> 8: Harrison, William
> 9: Tyler, John
> 10: Polk, James
> 11: Taylor, Zachary
> 12: Filmore, Millard
> 13: Pierce, Franklin
> 14: Buchanan, James
>
>
> Retrieve class from Vector.
> 0: Buchanan, James
> 1: Buchanan, James
> 2: Buchanan, James
> 3: Buchanan, James
> 4: Buchanan, James
> 5: Buchanan, James
> 6: Buchanan, James
> 7: Buchanan, James
> 8: Buchanan, James
> 9: Buchanan, James
> 10: Buchanan, James
> 11: Buchanan, James
> 12: Buchanan, James
> 13: Buchanan, James
> 14: Buchanan, James
>
> --
> *******************************************
> * Rick Roberts                            *
> * Advanced Information Technologies, Inc. *
> *******************************************
>
>
>
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to