java - on my second class called next class, last line of public array list search for price the .indexOf double cant be dereferenced? -


i started looking result , getting title of book. when user enter keyword locate book , display author, price, , title of book. main issue value price trying indexof, , lower result down 1 book. advice appreciated.

   public arraylist<test> searchfortitle( string searchstring ) {     arraylist<test> searchresult = new arraylist<test>();     ( book currentbook : library )     {         if ( ( currentbook.gettitle() ).indexof( searchstring ) != -1 )         searchresult.add( currentbook );     }     searchresult.trimtosize();     return searchresult; }  public arraylist<test> searchforauthor( string searchstring ) {     arraylist<test> searchresult = new arraylist<test>();     ( test currentbook : library )     {         if ( ( currentbook.getauthor() ).indexof( searchstring ) != -1 )         searchresult.add( currentbook );     }     searchresult.trimtosize();     return searchresult; }      next class:       public static void main(string [] args ) {     bookstore bs = new bookstore();      string keyword = joptionpane.showinputdialog(null, "enter keyword"  );     system.out.println("our book collection is:");     system.out.println(bs.tostring());      arraylist<test> results = bs.searchfortitle(keyword);      system.out.println("the search results " + keyword + " are:");     for( test tempbook : results )     system.out.println(tempbook.tostring());     string author = joptionpane.showinputdialog(null, "enter author" );     results = bs.searchforauthor(author);      system.out.println("the search results " + author + " are:");     ( book tempbook : results)     system.out.println(tempbook.tostring());      double lowestprice = math.min(price);     string lowest = joptionpane.showmessagedialog(null,       "the lowest price           in bookstore is: " + lowestprice);     }     }    public arraylist<test> searchforprice( string searchstring )     {     arraylist<test> searchresult = new arraylist<test>();     ( book currentbook : library )     {         if ( ( currentbook.getprice() ).indexof( searchstring ) != -1 )         searchresult.add( currentbook );     }     searchresult.trimtosize();     return searchresult;    }    }        public test() {     title = "";     author = "";     price = 0.0; }  public test(string newtitle, string newauthor, double newprice ) {     title = newtitle;     author = newauthor;     price = newprice; }  public string gettitle() {     return title; }  public string getauthor() {     return author; }  public double getprice() {     return price; }  public string tostring() {     return ("title: " + title + "\t" + "author: " + author + "\t" +  "price: " + price ); }      } 

i think line:

 if ( ( currentbook.getprice() ).indexof( searchstring ) != -1 ) 

you search within double-value string cause searchstringis type stringand getprice()returns double value. not solution ;)


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -