Issues with starting a loop to create a contact
Hi, I am trying to create an address book with user input through the console.
I have setup a class called Contact and I am calling an array of 100 slots. I am to the point where I have user input to get a list of options such as add, delete, list, and save contacts. But I can't seem to get any of the loops to work and am stuck. I have the user press h to show options and then a to add a contact and the program is terminated.
class Contact {
String first_name;
String last_name;
String cell;
String age;
String state;
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader keyboard = new BufferedReader(in);
Contact(String fn){
first_name=fn;
}
void addContact() throws IOException{
System.out.println("What is the contacts First Name?");
first_name = keyboard.readLine();
System.out.println("What is the contacts Last Name?");
last_name = keyboard.readLine();
System.out.println("What is the cell number?");
cell = keyboard.readLine();
System.out.println("What is the contacts age?");
age = keyboard.readLine();
System.out.println("What state were they born?");
state = keyboard.readLine();
}
}
public class contactlist {
public static void main(String[] args) throws IOException {
//declaration of the array
Contact contacts[] = new Contact[100];
//creating the slots for the array
for(int I=0; I<contacts.length; I++){
contacts[i] = new Contact("xx");
}
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader keyboard = new BufferedReader(in);
System.out.println("Welcome to the address book program, press h to see options");
String options= keyboard.readLine();
if(options.equalsIgnoreCase( "h")){
System.out.println("Here are the options:");
System.out.println("Press A to add a new contact");
System.out.println("Press L to list all contacts");
System.out.println("Press D to delete a contact");
System.out.println("Press S to save contacts to a file");
options.equals(keyboard.readLine());
}
if(options.equalsIgnoreCase("a")){
System.out.println("recognized you pressed a");
for(int I=0; I<contacts.length;i++){
System.out.println("started for loop");
if(contacts[i].first_name.equals("xx")){
contacts[i].addContact();
break;
}
else{
I++;
}
}
}
}