Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aula1;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Scanner;
- import java.util.Hashtable;
- import java.util.Collection;
- public class Agenda {
- Scanner sc = new Scanner(System.in);
- //Criação das Hashtables necessárias para a agenda
- private Hashtable agendaCC;
- private Hashtable agendaNome;
- //Collection para representar função values
- private Collection<Pessoa> agendaCC1;
- private Collection<Pessoa> agendaNome1;
- public Agenda(){
- agendaCC = new Hashtable();
- agendaNome = new Hashtable();
- }
- public void novas(){
- System.out.println("Nome: ");
- String nome = sc.nextLine();
- System.out.println("CC: ");
- int cc = sc.nextInt();
- sc.nextLine();
- //Verificação da Data
- boolean Check = false; // assumimos que a data é inválida para começar o ciclo
- Data dataNasc;
- do{
- System.out.println("Data de nascimento (dd/mm/aaaa):");
- String DataNasc = sc.nextLine();
- dataNasc = new Data(DataNasc);
- if(dataNasc.Valida())
- Check = true;
- }while(!Check);
- //Criação de nova pessoa
- Pessoa nova = new Pessoa(nome,cc,dataNasc);
- //inserir na Hashtable
- agendaCC.put(cc, nova);
- agendaNome.put(nome,nova);
- }
- public void apagar(){
- System.out.println("Insira o nome da pessoa que pretende remover");
- String nome = sc.nextLine();
- Pessoa toRemove = (Pessoa) agendaNome.get(nome);
- agendaCC.remove(toRemove.cc());
- agendaNome.remove(toRemove.nome());
- }
- private void apre(){ //Collection's servem para representar a função values
- agendaCC1 = agendaCC.values();
- agendaNome1 = agendaNome.values();
- }
- public void ordCC(){
- Object[] t = agendaCC1.toArray();
- Pessoa tmp;
- for(int i = 0; i < t.length; i++){
- tmp = (Pessoa) t[i];
- tmp.print();
- }
- }
- public void printPessoas(){
- Object[] n = agendaNome1.toArray();
- Pessoa tmp;
- for(int i = 0; i < n.length; i++){
- tmp = (Pessoa) n[i];
- tmp.print();
- }
- }
- public void ordNome(){
- Object[] n = agendaNome1.toArray();
- Pessoa tmp;
- for(int i = 0; i < n.length; i++){
- tmp = (Pessoa) n[i];
- tmp.print();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement