I created 3 vectors, one for name, and the other for day and month of birth.
I fill in the 3 through the first menu option I made with switch case
, the second option would be to display only the names of who is registered (inserted) in the name vector: calendar, but it does not work, however when it is outside the conditional structure it works.
When I put in any structure the vector is not displayed, as if it were empty. What do I do?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author lab1
*/
import java.util.Scanner;
public class q3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner scan = new Scanner(System.in);
int tecla = 1;
while (tecla != 27){
System.out.println("**********Agenda de aniversariantes**************");
System.out.println("1.Cadastrar pessoa na agenda");
System.out.println("2.Excluir pessoa a partir do nome");
System.out.println("3.Consultar aniversariantes de uma data (dia e mês)");
System.out.println("4.Consultar aniversariantes por mês");
System.out.println("5.Consultar aniversariantes pela letra inicial do nome");
System.out.println("6.Mostrar toda a agenda ordenada pelo nome");
System.out.println("7.Mostrar toda a agenda ordenada pelo mes");
System.out.println("8.Sair");
System.out.println("A agenda pode suportar até 10 pessoas");
String agenda[] = new String[10];
int dia[] = new int[10];
int mes[] = new int[10];
System.out.print("Digite uma opção:");
int opcao = scan.nextInt();
switch(opcao){
case 1:
int i = 0;
// if(i < 10){
System.out.print("Digite o nome: ");
agenda[i] = scan.next();
System.out.print("Digite o dia do aniversario: ");
dia[i] = scan.nextInt();
System.out.print("Digite o mes do aniversario: ");
mes[i] = scan.nextInt();
i++;
//}
// else
// System.out.println("Agenda cheia");
break;
case 2:
int j;
for (j=0;j<agenda.length;j++)
if(agenda[0] == null)
System.out.println("Agenda vazia");
else{
System.out.println("Agenda de aniversários");
for (j=0;j<agenda.length;j++){
System.out.println(agenda[j]);
System.out.println(dia[j]);
System.out.println(mes[j]);
}
}
break;
}
}
}
}