Results 1 to 8 of 8
  1. #1
    jimmy91 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default help me check any wrong!

    //when i store item i arr[0] and arr[1]...i go search there seach by id1 can but when search id2 cannot display help correct my mistake thx



    import java.util.Scanner;
    public class TestAsset {
    public static int count=0;
    static Asset [] arr = new Asset[100];
    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

    mainPge();

    }
    public static void add(){

    System.out.print("\n\t\t\t -->ADD RECORDS<--\n");
    System.out.print("\t\t\t~~~~~~~~~~~~~~~~~~~\n");
    System.out.print("\t\tAssetId :");
    int id1 = scan.nextInt();
    System.out.print("\t\tDescription :");
    String des = scan.next();
    System.out.print("\t\tYear :");
    int Y = scan.nextInt();
    System.out.print("\t\tMonth :");
    int M = scan.nextInt();
    System.out.print("\t\tDay :");
    int D = scan.nextInt();
    System.out.print("\t\tOrderNumber :");
    int OrNo = scan.nextInt();
    System.out.print("\t\tPrice :");
    double P = scan.nextDouble();
    System.out.print("\t\tStatus :");
    String Stat = scan.next();


    System.out.print("\n\t\tAre you sure to save this record?[y]-y/[n]-no: ");
    String Q = scan.next();
    //To compare two strings for equality, use equals( ).

    if(Q.equalsIgnoreCase("y")) {
    arr[count] = new Asset(id1,des,D,M,Y,OrNo,P,Stat);
    count++;
    mainPge();

    }else if(Q.equalsIgnoreCase("n")){
    mainPge();
    }

    }
    public static void seach(){

    int D1 = 0;
    boolean seach1=false;
    int i=0;
    System.out.print("\n\t\t\t -->SEARCH RECORDS<--\n");
    System.out.print("\t\t\t~~~~~~~~~~~~~~~~~~~\n");
    System.out.print("\t\tEnter Asset Id You Want to Search :");
    int input = scan.nextInt();
    for( i=0 ; i<=arr.length ;i++){
    seach1 = arr[i].equals(input);

    if(seach1== true){
    D1=i;
    System.out.print("\n"+arr[D1]);
    }


    else {

    System.out.print("\n\t\tID Number not found!\n\n");

    mainPge();
    }


    System.out.print("\n\t\tAre You Want To Go Back To Main Menu?[y]-y/[n]-no: ");
    String P = scan.next();
    if(P.equalsIgnoreCase("y")) {
    mainPge();

    }else if(P.equalsIgnoreCase("n")){
    System.out.print("\t\tGood Bye! have A Nice Day");
    }
    }


    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Java Code:
    int input = scan.nextInt();
    for( i=0 ; i<=arr.length ;i++){
        seach1 = arr[i].equals(input);
    
        if(seach1== true){
            D1=i;
            System.out.print("\n"+arr[D1]);
        } else {
            System.out.print("\n\t\tID Number not found!\n\n");
            mainPge();
        }
    I think this is the problem area, but your lack of CODE tags makes it hard to follow.
    If it is then there's a couple of problems.
    First: "seach1 = arr[i].equals(input);"
    Your array is of Asset. Does the Asset equals() method compare Asset with Integer? I'm guessing not, so this will always fail.
    Second:
    Your loop seems all over the place. If the first entry does not match you straight away go and pop up the "not found" message. That message should only occur once you have exited the loop.

    I expect there are more, but the lack of formatting makes it too hard to tell.

  3. #3
    jimmy91 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    problem is now i save 2 record 1st record when i search i can get the information but 2nd record i cant search just pop out ID Number not found!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Did you not understand my post then?
    The first part seems to be covered since I'm guessing you have given Asset its own equals() method.

    But in the Second part I pointed out that you are doing the if/else each time round the loop...so if the id does not match the first one you go into the else and get the "not found" result. You need to rework that loop so the "not found" bit is outside the loop.

  5. #5
    jimmy91 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    thx alot i selltle
    but now i want asking
    i can add


    System.out.print("\n\t\t\t -->ADD RECORDS<--\n");
    System.out.print("\t\t\t~~~~~~~~~~~~~~~~~~~\n");
    System.out.print("\t\tAssetId :");
    int id1 = scan.nextInt();
    System.out.print("\t\tDescription :");
    String des = scan.next();
    System.out.print("\t\tYear :");
    int Y = scan.nextInt();
    System.out.print("\t\tMonth :");
    int M = scan.nextInt();
    System.out.print("\t\tDay :");
    int D = scan.nextInt();
    System.out.print("\t\tOrderNumber :");
    int OrNo = scan.nextInt();
    System.out.print("\t\tPrice :");
    double P = scan.nextDouble();
    System.out.print("\t\tStatus :");
    String Stat = scan.next();

    if i ask user change is
    arr[i] = new Asset(idEdit,desEdit,DEdit,MEdit,YEdit,OrEdit,PEdi t,StEdit);
    but status now i dont want to ask user change

    but at my edit function i want to ask user edit all but the status part i don't want to ask user change how can i do

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    I'm sorry I didn't understand that.

  7. #7
    jimmy91 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    1st i got add ,edit , delet and view function !
    the at add function got ask user enter ID,date ,order number and status...
    this entry is in 1 array.
    when to store new data enter by user is >> arr[i] = new Asset(id,data,Oder number, status ); right?
    so my question is i just want ask user edit the 1st 3 data only(id,date,..) but the status i dont want ask user to edit!
    so when i want to store the new user edit data to that arr asset() wat can i do?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    For editing you want to find the Asset in the array (presumably the user gives you the id of the one to edit?), then do arr[index of asset to edit].setId(), or setDate() or setOrderNumber(). That is assuming that Asset has setter methods for those things(as it should do if written correctly).

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. pls check it
    By aRTx in forum New To Java
    Replies: 0
    Last Post: 03-24-2009, 02:35 PM
  3. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  4. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 0
    Last Post: 11-14-2008, 01:22 PM
  5. Check box tag
    By elizaabru in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-26-2008, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •