import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class Final1 extends Applet implements ActionListener
{
   private int n = 0;
   private Label Title;
   private TextField Name, Addr, Tel;
   private ContactList contactList;
   private Contact contact[];
   private Button AddList, Print;   

   public void init()
   {
      contact = new Contact[10];
      contactList = new ContactList();

      setSize( 300, 150 );
      setLayout( new GridLayout( 5, 2 ) );

      add( new Label( "Name: " ) );
      Name = new TextField();
      Name.setEditable( true );
      add( Name );

      add( new Label( "Address: " ) );
      Addr = new TextField( 50 );
      Addr.setEditable( true );
      add( Addr );      

      add( new Label( "Phone Number: " ) );
      Tel = new TextField( 20 );
      Tel.setEditable( true );
      add( Tel );

      AddList = new Button( "Add" );
      AddList.addActionListener( this );
      add( AddList );      

      Print = new Button( "Print" );
      Print.addActionListener( this );
      add( Print );       
   }

   public void actionPerformed( ActionEvent e )
   {
      if ( e.getSource() == AddList )
      {
         if( n < 10 )
         {
            contact[n] = new Contact( Name.getText(), Addr.getText(), Tel.getText() );
            contactList.push( contact[n] );
            Name.setText("");
            Addr.setText("");
            Tel.setText("");
            n++;
         }
      }
      else
         contactList.print();
   }
}

class Contact
{
   private String Name, Addr, Tel;
   Contact(String o1, String o2, String o3 )
   {
     Name = o1;
     Addr = o2;
     Tel = o3;
   }
   public String getName() { return Name; }
   public String getTel() { return Tel; }
   public String getAddr() { return Addr; }
}

class ContactNode
{
   Contact data;    
   ContactNode next;

   ContactNode( Contact c ) { this( c, null ); }

   ContactNode( Contact c, ContactNode nextNode )
   {
      data = c;       
      next = nextNode; 
   }

   Contact getObject() { return data; }

   ContactNode getnext() { return next; }
}

class ContactList
{
   private ContactNode firstNode;
   private ContactNode lastNode;

   public ContactList( String s )  { firstNode = lastNode = null; }

   public ContactList() { this( "ContactList" ); }

   public void push( Contact insertItem )
   {
      if ( isEmpty() )
         firstNode = lastNode = new ContactNode( insertItem );
      else 
         lastNode = lastNode.next = new ContactNode( insertItem );
   }

   public boolean isEmpty() { return firstNode == null; }

   public void print()
   {
      if ( isEmpty() ) {
         System.out.println( "Empty List " );
         return;
      }
 
      ContactNode current = firstNode;

      while ( current != null ) {
         System.out.print( current.data.getName() + "\n" );
         System.out.print( current.data.getAddr() + "\n" );
         System.out.print( current.data.getTel() + "\n" );
         System.out.print( "\n" );

         current = current.next;
      }
   }
}