Ciao; questo è un semplice esempio.... non l'ho provato ma dovrebbe funzicare.
Ciao
codice:
public class Utente {
private String nome;
private String cognome;
private String via;
private String telefono;
public Utente( String _nome, String _cognome, String _telefono, String _via ) {
setNome( _nome );
setCognome( _cognome );
setTelefono( _telefono );
setVia( _via );
}
public void setNome( String value ){
nome = value;
}
public String getNome(){
return nome;
}
public void setCognome( String value ){
cognome = value;
}
public String getCognome(){
return cognome;
}
public void setVia( String value ){
via = value;
}
public String getVia(){
return via;
}
public void setTelefono( String value ){
telefono = value;
}
public String getTelefono(){
return telefono;
}
public String toString( ){
return "Nome utente: "+ getNome()+" cognome: "+ getCognome()+" telefono: "+getTelefono()+" indirizzo: "+getVia();
}
}
codice:
import java.util.Hashtable;
public class Main {
public static void main(String[] args) {
if( args.length < 1 ){
System.out.println( "Inserire il nome....." );
System.exit(0);
}
Hashtable h = new Hashtable();
h.put( "Pippo", new Utente( "Pippo", "Pelo", "0245", "via alcide" ) );
h.put( "Pluto", new Utente( "Pluto", "Cane", "0245", "via topi" ) );
h.put( "Topolino", new Utente( "Topolino", "Top", "0245", "topolinia" ) );
if( h.containsKey( args[0] ) ){
Utente u = ( (Utente)( h.get( args[0] ) ) );
System.out.println( u );
}else{
System.out.println( "Passato un nome non in rubrica" );
}
}
}