Ask Experts Questions for FREE Help !
Ask
    fayjk's Avatar
    fayjk Posts: 1, Reputation: 1
    New Member
     
    #1

    Nov 25, 2014, 09:42 PM
    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++;
    }
    }
    }
    }

Check out some similar questions!

Suggestions on immediately starting No Contact with Ex vs waiting? [ 11 Answers ]

Ok we are not really exes, but we have been friends with benefits for a year and a half... I met her through my sister, she is 21 and I am 25. At first it was only a physical thing, and we began getting really close till the point she told me she loved me, and after a while I began to feel the say...

Starting No contact 8 weeks after breakup [ 3 Answers ]

I was with ex for 6 years and we have a child and a house. He broke up with me 8 weeks ago as he met someone else. I was devastated, heartbroken, angry... the usual I'm sure. I moved out with our daughter, found a new place to live and have been doing OK. We fought a lot to start with as I was...

Starting issues [ 1 Answers ]

The flywheel on my riding mower sticks when I try to start it. What can I do?

Starting issues [ 1 Answers ]

:( I have a 1996 White lawn tractor model L-12. It won't turn over fast enough to start. I have replaced the battery due to it setting for the past 3 yrs. It starts fine with the help of a jump. It runs fine. The new battery shows it's putting out 12V. The output side of the old solenoid showed...

13.5 HP B/S Starting Issues [ 5 Answers ]

I have a 13.5 HP Briggs & Stratton motor that after sitting for a while, will start for a second or two then shut off. I have replaced the spark plug which is getting a spark. I have checked the fuel lines which are flowing correctly and replaced the fuel filter. If I pour gasoline straight into...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.