This is one of my first java programs, which includes a GUI and an linear array (I hope!)
I know this isn't suppose to be a 'help' website but more of a place to collaborate ideas, but I've been staring my eyes out for the past hour and a half with little to no progress on my problem (which I will get too momentarily) The funny being it's probably not even the hardest bit of the program.
So I'm hoping you guys can help me figure this out. I've created a fairly simple program that most I've already written, and after completion of the program the user can input a number in (enterNumberField) choosing numbers from the linearArray (1, 2, 31 or 35) and after pressing a button, the program outputs either A, B, C or D in the textField I've dubbed 'ItsAField' (creative I know).
Unfortunately, no matter what number is chosen it always outputs as D.
public class ChildrensClassicsView extends FrameView {
String [] linearArray = {"1", "2", "31", "35"}; //numbers to choose from
}
static public Boolean linearSearch (String [] A, String B) {
for (int k=0; k<A.length; k++) {
if (A[k].equals(B)) {
return true;
}
}
return false;
}
After pressing action performed button...
It wouldn't surprise me if it was just a problem with these 'if statements' however I'm not even sure if you can use them like this to get the answer I'm looking for. Am I on the right track for outputting the 'chosen' variable?
private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {
String input = enterNumberField.getText();
if (input.equals("1")) {
ItsAField.setText("Search: A " + linearSearch(linearArray, "1"));
}
if (input.equals("2")) {
ItsAField.setText("Search: B " + linearSearch(linearArray, "2"));
}
if (input.equals("28")){
ItsAField.setText("Search: C " + linearSearch(linearArray, "31"));
} else {
ItsAField.setText("Search: D " + linearSearch(linearArray, "35"));
}
I also have my figures crossed hoping this still qualifies as a real question :)