Monday, July 27, 2009

Any pro java programmer i need your help?

why when i add private int yearpublished; my program has an error why it's, it has no error when i add a new String data type the problem is when i add a int data type








// to run this program: C%26gt;java libmainsys


//////////////////////////////////////...





/////////


class libary


{


private String booktitle;


private String bookauthor;


private String publisher;


private int yearpublished;


private int nofcop;





public libary(String title, String author, String





pub, int yrpub, int nfcp)


{ // constructor


booktitle = title;


bookauthor = author;


publisher = pub;


yearpublished = yrpub


nofcop = nfcp;


}





public void displaylibary()


{


System.out.print(" Book Title: " + booktitle);


System.out.print(", Book Author: " + bookauthor);


System.out.print(", Book Publisher: " + publisher);


System.out.print(", Year Published: " +





yearpublish);





System.out.println(",No Of Copies : " + nofcop);


}

Any pro java programmer i need your help?
Your problem is not on the "int" type but on the "insert" parameter to your array!


You gave there insert(String, String, String, String , int) but your class has constructor supports only (String, String, String, int, int)... So the last "String" argument on your insert should be without quotes (an "int" value).





Edit:





for example:


arr.insert("Web_Publishing", "Audrey_Cynthia", "Surg", "193", 2001);





should be





arr.insert("Web_Publishing", "Audrey_Cynthia", "Surg", 193, 2001);


this is according to the definition of your insert method. I hope you see the diference between the 2 examples.


No comments:

Post a Comment