java - code efficiency, debugging, objects methods, arrays -


i practicing more objects, arrays, , methods. right writing simple book keeping program add book, search books title, author, price, inventory number, , genre. have few questions on one, fixing program (adding book in method fillbook(), two, how delete book object class, , three, how can make program more efficient.

researching, , reading on ioexception class.


this error getting
java:66: error: constructor book in class book cannot applied given types;
book tempbook = new book();
^
required: string,string,double,int,string
found: no arguments
reason: actual , formal argument lists differ in length
1 error

tool completed exit code 1

template object class

public class book { private string title; private string author; private double price; private int inventorynumber; private string category;  private static int numberofbooks = 0;  public book(string booktitle, string bookauthor, double bookprice, int bookinventorynumber, string bookcategory) {     title = booktitle;     author = bookauthor;     price = bookprice;     inventorynumber = bookinventorynumber;     category = bookcategory;     numberofbooks++; }//end 5 args book constructor  public string gettitle()  {return title;} public void settitle(string t)  {title = t;}  public string getauthor() {return author;} public void setauthor(string a)  {author = a;}  public double getprice() {return price;} public void setprice(double p)  {price = p;}  public int getinventorynumber() {return inventorynumber;} public void setinventorynumber(int i)  {inventorynumber = i;}  public string getcategory()  {return category;} public void setcategory(string c)  {category = c;}  public static int getnumberofbooks()  {return numberofbooks;}  public string tostring () {     stringbuffer sb = new stringbuffer();     sb.append("title: " + title);     sb.append("\nauthor: " + author);     sb.append("\nprice: " + price);     sb.append("\ninventorynumber: " + inventorynumber);     sb.append("\ncategory: " + category + "\n\n");     return (new string (sb)); }//end tostring  public static string searchbytitle(book[] newbook, string seachname) {     string message = "";     for(int i=0; i<getnumberofbooks(); i++)     {         if (seachname.equalsignorecase(newbook[i].gettitle()))         {             message += newbook[i].tostring();         }//end if     }//end     return message; }//end searchbytitle  public static string searchbyauthor(book[] newbook, string seachname) {     string message = "";     for(int i=0; i<getnumberofbooks(); i++)     {         if (seachname.equalsignorecase(newbook[i].getauthor()))         {             message += newbook[i].tostring();         }//end if     }//end     return message; }//end searchbyauthor  public static string searchbyprice(book[] newbook, double seachprice) {     string message = "";     for(int i=0; i<getnumberofbooks(); i++)     {         if (seachprice == newbook[i].getprice())         {             message += newbook[i].tostring();         }//end if     }//end     return message; }//end searchbyprice  public static string searchbyinventory(book[] newbook, int seachinventory)     {         string message = "";         for(int i=0; i<getnumberofbooks(); i++)         {             if (seachinventory == newbook[i].getinventorynumber())             {                 message += newbook[i].tostring();             }//end if         }//end         return message; }//end searchbyinventory  public static string searchbycategory(book[] newbook, string seachname)     {         string message = "";         for(int i=0; i<getnumberofbooks(); i++)         {             if (seachname.equalsignorecase(newbook[i].getcategory()))             {                 message += newbook[i].tostring();             }//end if         }//end         return message; }//end searchbyauthor  }//end class 

run program class

import javax.swing.joptionpane;  class findbook { public static void main(string[] args) {     book[] newbook = new book[2000];     newbook[0] = new book("game of thrones", "george r. r. martin", 39.95, 3, "fiction");     newbook[1] = new book("a song of ice , fire", "george r. r. martin", 34.50, 3, "fiction");     newbook[2] = new book("java programming dummies", "donald koosis", 59.29, 12, "non fiction");     newbook[3] = new book("java™ programming: problem analysis program design, 5th edition", "malik", 140.49, 4, "non fiction");     newbook[4] = new book("life of pi", "yann martel", 12.50, 3, "childrens");      boolean continueoption = true;     //****************menu bar********************/     {         int menuoption = getmenu();         switch (menuoption)         {             case 1: addbook(newbook); break;             case 2: searchbytitle(newbook); break;             case 3: searchbyauthor(newbook); break;             case 4: searchbyprice(newbook); break;             case 5: searchbyinventory(newbook); break;             case 6: searchbycategory(newbook); break;             case 7: displayallbookinfo(newbook); break;             case 8: continueoption = false; break;             default: joptionpane.showmessagedialog(null, "invalid choice"); break;         }//end menu     }while (continueoption);      joptionpane.showmessagedialog(null, "thank come again");  }//end main  public static int getmenu() {     string message;     int choice;     message = "\n1. add book in book database: \n"     + "2. search book database title: \n"     + "3. search books database author: \n"     + "4. search books database price: \n"     + "5. search books database inventory: \n"     + "6. search books database category: \n"     + "7. display book information: \n"     + "8. exit program\n\n"     + "please enter in number menu choose.";     choice = integer.parseint(joptionpane.showinputdialog(null,message));     return choice; } // end getmenu method  // option add book public static void addbook(book[] abook) {     int select;     do{         abook[book.getnumberofbooks()] = fillbook();         select = joptionpane.showconfirmdialog(null, "add book?");     }while (select == joptionpane.yes_option && book.getnumberofbooks() < 2000); }//end method add book  //filling in book book array public static book fillbook() {     book tempbook = new book();     tempbook.settitle(joptionpane.showinputdialog(null, "enter title"));     tempbook.setauthor(joptionpane.showinputdialog(null, "enter author"));     tempbook.setprice(double.parsedouble(joptionpane.showinputdialog(null, "enter in price")));     tempbook.setinventorynumber(integer.parseint(joptionpane.showinputdialog(null, "enter in how many book(s) in inventory")));     tempbook.setcategory(joptionpane.showinputdialog(null, "enter in category"));     return tempbook; }//end fillbook   public static void searchbytitle(book[] abook) {     string message = "";     string searchtitle = "";     searchtitle = joptionpane.showinputdialog(null, "what title want search for?");     message = book.searchbytitle(abook, searchtitle);     joptionpane.showmessagedialog(null, message); }//end method searchbytitle  public static void searchbyauthor(book[] abook) {     string message = "";     string searchauthor = "";     searchauthor = joptionpane.showinputdialog(null, "what author want search for?");     message = book.searchbyauthor(abook, searchauthor);     joptionpane.showmessagedialog(null, message); }//end method searchbyauthor  public static void searchbyprice(book[] abook) {     string message = "";     double searchprice = double.parsedouble(joptionpane.showinputdialog(null, "what author want search for?"));     message = book.searchbyprice(abook, searchprice);     joptionpane.showmessagedialog(null, message); }//end method searchbyprice  public static void searchbyinventory(book[] abook) {     string message = "";     int seachinventory = integer.parseint(joptionpane.showinputdialog(null, "what author want search for?"));     message = book.searchbyinventory(abook, seachinventory);     joptionpane.showmessagedialog(null, message); }//end method searchbyinventory  public static void searchbycategory(book[] abook) {     string message = "";     string searchcategory = "";     searchcategory = joptionpane.showinputdialog(null, "what author want search for?");     message = book.searchbycategory(abook, searchcategory);     joptionpane.showmessagedialog(null, message); }//end method searchbycategory  public static void displayallbookinfo(book[] abook) {     string message ="";     for(int i=0; i<book.getnumberofbooks(); i++)     {         message += abook[i].tostring();     }//end loop displayallbookinfo     joptionpane.showmessagedialog(null, message); }//end method displayallbookinfo   }//end class 

you need add default constructor book class. once provide parameterized constructor, java not automatically create default conatructor, need provide it.

book tempbook = new book(); start working once provide below constructor in class.

public book(){ //implementation } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -