Results 1 to 8 of 8
Thread: help me check any wrong!
- 11-15-2010, 02:02 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
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");
}
}
}
- 11-15-2010, 03:01 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
I think this is the problem area, but your lack of CODE tags makes it hard to follow.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(); }
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.
- 11-15-2010, 03:05 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
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!
- 11-15-2010, 03:42 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 11-16-2010, 11:45 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
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
- 11-16-2010, 11:57 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
I'm sorry I didn't understand that.
- 11-16-2010, 12:16 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
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?
- 11-16-2010, 12:54 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 4Last Post: 06-11-2013, 01:37 AM -
pls check it
By aRTx in forum New To JavaReplies: 0Last Post: 03-24-2009, 02:35 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum New To JavaReplies: 2Last Post: 11-14-2008, 07:53 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 0Last Post: 11-14-2008, 01:22 PM -
Check box tag
By elizaabru in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-26-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks