Erm can't you just compare it as a string instead of converting it to an integer:
For example
if(seatNo.equals("7-20"))
{
print("you have chosen economy class")
}
or something akin to this?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
That won't work, iamthwee, because you're comparing only the entire range and not subranges thereof.
Think about what you're actually doing here. What's happening with the result of Integer.parseInt()?
What are you comparing with those hardcoded limits?
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Oh I see what you mean, didn't read it properly.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Just a quick one, not sure...
Operator < cannot be applied to (java.lang.String[], int)
Would tell me you're trying to compare a string against an int.
Can't do that. So make sure this -> java.lang.String[] is actually an integer.
Although you've converted in to an integer here:
Integer.parseInt(seatNo[i]);
you're still comparing the actual String?
try this...
//this is where the error occurs and I just can't figure out how to solve it
for (int i = 0; i < seatNo.length; i++) {
int k;
k= Integer.parseInt(seatNo[i]);
if (jRBSeatBiz.isSelected() && (k < 1 || k > 6)) {
return "- Business class seat no should be 1- 6\n";
}
I have not tested this so it may not work.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
So this means that i cant use < or > operators to compare the INTEGERS in the STRING array!
You're trying to compare integers to strings, that's not going to work.
An integer isn't a string after all, and the compilers tells you just that.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
I tried to do a System.out.println(seatNo[i]) before the comment part and it prints out
1
2
when I entered in 1-2 in the seat number, so this means the split works, but i have issues with validating the seat type.
You're converting the string to an int, but then try to compare the string to your boundary conditions.
Why? Aren't you missing something there?
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337