Pessoa pessoa ajuda de vcs, estou iniciando num curso q achei na internet sobre java e consigo fazer um programa simples e compilar ele, mas agora quando pego um programa tipo esse nao da certo, sera q alguem pode me ajudar a compilar isso aqui:
Bom eu vo por igual como tava na apostila ok.
La não fala se é um arquivo só, se são 3 não explica nada. Bom la vai os Arquivos.
primeiro:
Pessoa.java
/**
Pessoa
*/
public class Pessoa
{
private String Nome;
private String Tel;
private String End;
//Contrutor
public Pessoa(String n, String t, String e)
{
Nome = n; Tel = t; End = e;
}
/**
getNome
*/
public String GetNome(){return Nome;}
/**
getNome
*/
public String getTel(){return Tel;}
/**
getEnd
*/
public String getEnd(){return End;}
}
Segundo:
Agenda.java
/**
AGENDA Versao Console 2.0
/
import java.util.;
public class Agenda
{
Hashtable pessoas;
//Contrutor
public Agenda() {pessoas = new Hashtable();}
/**
Inserir
*/
public void inserir(Pessoa p) {pessoas.put(p.getNome(),p);}
/**
Consultar
*/
public Pessoa getPessoa(String nome)
{return (Pessoa) pessoas.get(nome);}
/**
Listar
*/
public Enumeration getPessoas(){return pessoas.elements();}
}
Terceiro:
AgendaInt.java
/**
AgendaInt
Interface console da agenda.
*/
import java.io.;
import java.util.;
public class AgendaInt
{
Agenda ag;
BufferedReader in;
// Construtor
public AgendaInt()
{
ag = new Agenda();
in = new BufferedReader(new InputStreamReader(System.in));
}
/**
Exibir lista
*/
public void Exibirlista()
{
Pessoa p;
for (Enumeration e = ag.getPessoas(); e.hasMoreElemtents();)
{
p = (Pessoa) e.nextElement();
System.out.println("\nNome:"+p.getNome()+"\nTelefone:"+p.getTel()+"\nEndereço:"+p.getEnd()+"\n");
}
}
/**
exibirPessoa
*/
public void exibirPessoa()
{
String nome=null;
try {
System.out.println("Entre com o nome:");
nome = in.readLine();
if (nome.length()<1) System.exit(-1);
} catch(IOException e)
{System.out.println(e.getMessage());System.exit(-1);}
Pessoa p = ag.getPessoa(nome);
if (p!=null)
{
System.out.println("\nNome:"+p.getNome()+"\nTelefone:"+p.getTel()+"\nEndereço:"+p.getEnd());
}
}
/**
obterPessoa
*/
public void obterPessoa()
{
String nome;
String tel;
String end;
try {
System.out.println("Entre com o nome:");
System.out.flush();
nome = in.readLine();
if (nome.length()<1) System.exit(-1);
System.out.println("\nEntre com o Telefone:");
System.out.flush();
tel = in.readLine();
System.out.println("\nEntre com o Endereço:");
System.out.flush();
end = in.readLine();
ag.inserir(new Pessoa(nome,tel,end));
} catch(IOException e)
{System.out.println(e.getMessage());System.exit(-1);}
}
/**
gravar
*/
public void gravar()
{
try
{
Pessoa p;
BufferedWriter fout = new BufferedWriter(
new FileWriter("agenda.dat"));
for (Enumeration e = ag.getPessoas();
e.hasMoreElements();)
{
p = (Pessoa) e.nextElement();
fout.write(p.getNome()+"\n"+p.getTel()+"\n"+p.getEnd()+"\n");
}
fout.flush();
fout.close();
}catch(FileNotFoundException e)
{System.out.println("Arq. nao encontrado");}
catch(IOException e)
{System.out.println("Erro na gravação!");}
}
/**
Carregar
*/
public void carregar()
{
try
{
String nome;
String tel;
String end;
BufferedReader fin = new BufferedReader(
new FileReader("agenda.dat"));
while ((nome = fin.readLine()) != null)
{
tel = fin.readLine();
end = fin.readLine();
ag.inserir(new Pessoa(nome,tel,end));
}
fin.close();
}catch(FileNotFoundException e)
{System.out.println("Arq. nao encontrado");}
catch(IOException e)
{System.out.println("Erro na leitura!");}
}
//main
public static void main(String args[])
{
AgendaInt agInt = new AgendaInt();
String opcao="";
for(;;)
{
System.out.println(
"\nAgenda Tabajara\n***************************\n");
System.out.print("Opcoes:\n(i)nserir\n(c)onsultar"+
"\n(l)istar\n(g)ravar\n(r)ecuperar\n(f)im=>");
System.out.flush();
try
{
opcao = agInt.in.readLine();
if (opcao.length()==0) continue;
}catch(IOException e)
{System.out.println(e.getMessage());System.exit(-1);}
switch(opcao.charAt(0))
{
case 'f' : System.exit(0);break;
case 'i' : agInt.obterPessoa(); break;
case 'c' : agInt.exibirPessoa(); break;
case 'l' : agInt.Exibirlista(); break;
case 'g' : agInt.gravar(); break;
case 'r' : agInt.carregar(); break;
}
}
}
}
Bom ai estao eles, o primeiro compila, agora os outros dois nao compila.
Se alguem puder ajudar desde ja eu agradeço.
