java - Binary Search output issue? -


this first using binary search me, i've run small issue (hopefully!) first program, allows user type in random number, , if number matches book outputs title.

class b {      string book1, book2;      b () {         book1 = "wicked awesome title";         book2 = "how read book";          public static book getbook(book [] a, int left, int right, string booktitle) {             int middle;             book found = null;              /**your average joe binary search...*/             while (found == null && left <= right) {                 //if middle item == 0, returns true                 middle = (left + right)/2;                 int compare = a[middle].sametitle(booktitle);                 if (compare == 0) {                     found = a[middle];                 } else {                     if (compare >0) {                         right = middle -1;                     } else {                         left = middle + 1;                     }                 }             }             return found;         } 

now problem, after pressing "find" book button,

private void findactionperformed(java.awt.event.actionevent evt) {                                                 string book1 = "wicked awesome title";     string book2 = "how read book";;      book b = getbook(book1, book2); //this entire line underlined,      if (b != null){         itsatextfield.settext("you've found book " + b);     } 

so missing make work? ideas?

your getbook function declared as:

public static book getbook(book [] a, int left, int right, string booktitle) { 

when try call 2 string arguments:

book b = getbook(book1, book2); 

if want call function, must call expected arguments.

also, not sure if related or not you'r missing } @ end of constructor.

btw, adding error you.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -