dimanche 10 janvier 2016

my if statment is not activating, how do i fix this [duplicate]

This question already has an answer here:

my progect contains

  • readID();reads id from the id.txt
  • readDB();reads the database from the theDataBase.txt and inserts it into a ArrayList
  • find();try's to match the id with the corresponding id in the database. this is where the if statement is not activating ): it should activated in index 25 in the Arraylist

here is the find method that I'm having problems with

public void find(){
    int i;
    for(i=0;i<myList.size();i++){
        String id=myList.get(i);
        System.out.println(idNumber + " " + id);
        if(idNumber==id){
            System.out.println(myFName +" owns the ID because theres a match in in index " + i);
        }

    }
}

here is the rest of the code

    package dataBata;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Data {
    private static String idNumber;
    private static String myID, myLName, myFName, myMName, myType, myDate, x;
    private static int count=0;
    ArrayList<String> myList = new ArrayList<String>(10);

public void readID(){
    Scanner draw = null;
    try{
        draw = new Scanner(new File("id.txt"));
    }
    catch(Exception e){
        System.out.println("Could not find file!!!");
    }
    while(draw.hasNext()){
        idNumber=draw.next();
    }

    draw.close();
}

public void readDB(){
    Scanner draw = null;

    try{
        draw = new Scanner(new File("theDataBase.txt"));
    }
    catch(Exception e){
        System.out.println("Could not find file!!!");
    }

this is were I read the database.txt file in to the ArrayList that is called mylist

    int d = 0;
    while(draw.hasNext()){
        myID=draw.next();
        x=draw.next();
        myLName=draw.next();
        x=draw.next();
        myFName=draw.next();
        x=draw.next();
        myMName=draw.next();
        x=draw.next();
        myType=draw.next();
        x=draw.next();
        myDate=draw.next();
        x=draw.next();
        myList.add(myID);
        myList.add(myLName);
        myList.add(myFName);
        myList.add(myMName);
        myList.add(myType);
        myList.add(myDate);
        d++;
        count = d;

    }
}

the Int Main() part

    public static void main(String[] args) {
    Data A = new Data();
    Scanner tell = new Scanner(System.in);

    A.readDB();
    A.readID();
    A.find();

}

heres the id.txt file

3948685948

hers the theDataBase.txt file

5254796772 , davis             , sam                , J , staff    , 01/08/16 ,
5690043673 , claira            , jammy              , h , student  , 01/04/16 ,
5444444444 , bartholamul       , tom                , y , staff    , 01/07/16 ,
5363456784 , katy              , baker              , t , staff    , 01/05/16 ,
3948685948 , dixon             , isaac              , J , student  , 01/07/16 ,
3334445653 , squarpants        , spoongbob          , g , police   , 01/03/16 ,
8765443236 , jerry             , tom                , f , police   , 01/07/16 ,
9979957593 , dixon             , samuel             , a , staff    , 01/08/16 ,
2552556662 , dixon             , johnathan          , g , admin    , 01/07/16 ,
7777577576 , richards          , derran             , J , admin    , 01/01/16 ,

Aucun commentaire:

Enregistrer un commentaire