I have got errors which where commented in below program.Plz compile these program and cpy paste the code ... iam little bit confused... dudee....
import java.util.ArrayList;
import java.util.Scanner;
// To take customer detais by using Constructor and Customer deatils
class Customer {
int cusId;
String fName;
String lName;
long phNo;
int count;
int cbid;
public Object setcbid;
Customer(int id,String fn,String ln,long no,int count){
this.cusId = id;
this.fName = fn;
this.lName = ln;
this.phNo = no;
this.count=count;
}
public int getcusId(){
return this.cusId;
}
public String getfname(){
return this.fName;
}
public String getlname(){
return this.lName;
}
public long getphNo(){
return this.phNo;
}
public void setcbid(int i){
this.cbid=cbid;
}
public int getcbid(){
return this.cbid;
}
public int getcount(){
return this.count;
}
//to take book details by using Constructor and get methods
class Book
{
int bookId;
String title;
String status;
String bookType;
public String setstatus;
public Object bid;
Book (int bid,String title,String status,String booktype){
this.bookId=bid;
this.title=title;
this.status=status;
this.bookType=booktype;
}
public void setStatus(String s){
this.status=status;
}
public int getBookId(){
return this.bookId;
}
public String getTitle(){
return this.title;
}
public String getStatus(){
return this.status;
}
public String getBookType(){
return this.bookType;
}
}
// To create a main class ti allow user to do his operations
class Lib {
// creating an Arraylist for Customer & book
ArrayList<Customer> cl=new ArrayList<Customer>();
ArrayList<Book> bl=new ArrayList<Book>();
public static void main(String args[]){
/*
getting these errors in below statements
15 errors found:
File: C:\j2sdk1.4.2\bin\Lib.java [line: 85]
Error: C:\j2sdk1.4.2\bin\Lib.java:85: inner classes cannot have static declarations
File: C:\j2sdk1.4.2\bin\Lib.java [line: 90]
Error: C:\j2sdk1.4.2\bin\Lib.java:90: non-static variable cl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 91]
Error: C:\j2sdk1.4.2\bin\Lib.java:91: non-static variable cl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 92]
Error: C:\j2sdk1.4.2\bin\Lib.java:92: non-static variable cl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 93]
Error: C:\j2sdk1.4.2\bin\Lib.java:93: non-static variable cl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 94]
Error: C:\j2sdk1.4.2\bin\Lib.java:94: non-static variable cl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 97]
Error: C:\j2sdk1.4.2\bin\Lib.java:97: non-static variable bl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 97]
Error: C:\j2sdk1.4.2\bin\Lib.java:97: non-static variable this cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 98]
Error: C:\j2sdk1.4.2\bin\Lib.java:98: non-static variable bl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 98]
Error: C:\j2sdk1.4.2\bin\Lib.java:98: non-static variable this cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 99]
Error: C:\j2sdk1.4.2\bin\Lib.java:99: non-static variable bl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 99]
Error: C:\j2sdk1.4.2\bin\Lib.java:99: non-static variable this cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 100]
Error: C:\j2sdk1.4.2\bin\Lib.java:100: non-static variable bl cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 100]
Error: C:\j2sdk1.4.2\bin\Lib.java:100: non-static variable this cannot be referenced from a static context
File: C:\j2sdk1.4.2\bin\Lib.java [line: 107]
Error: C:\j2sdk1.4.2\bin\Lib.java:107: non-static variable this cannot be referenced from a static context
*/
//Adding Details to class Customer
cl.add(new Customer(519340,"Pallavi","priya",790074455,3));
cl.add(new Customer(519339,"Sravani","tuppu",564128374,2));
cl.add(new Customer(519343,"Pallavi1","priya1",790074456,1));
cl.add(new Customer(519346,"Pallavi2","priya2",790074458,0));
cl.add(new Customer(519335,"Pallavi3","priya3",790074425,5));
// Adding Details to class Book
bl.add(new Book (51934 , "Java","Available","Technical"));
bl.add(new Book (51933 , "WebTechnologies","Available","Technical"));
bl.add(new Book (51934 , "Managementskills","loaned","Management"));
bl.add(new Book (51936 , "Fiction1","Available","Fiction"));
System.out.println("1. LoanBook");
System.out.println("2. returnBook");
System.out.println("3. getCustomerWhoLoanedBook");
System.out.println("4. getTotalIssuedBookCount");
Lib o=new Lib();
System.out.println("Enter Your choice");
Scanner s=new Scanner(System.in);
int n=s.nextInt();
switch(n)
{
case 1:
System.out.println("Enter the Customer Id");
int id1=s.nextInt();
System.out.println("Enter the Book Id");
int bid1=s.nextInt();
boolean b1 = o.LoanBook (id1,bid1);
if(b1)
System.out.println("Book is Loaned Successfully");
else
System.out.println("Book is not loaned");
break;
case 2:
System.out.println("Enter the Customer Id");
int id2=s.nextInt();
System.out.println("Enter the Book Id");
int bid2=s.nextInt();
Boolean b = o.ReturnBook(id2,bid2);
if(b)
System.out.println("Book Returned Successfully");
else
System.out.println("Book not returned");
break;
case 3:
System.out.println("Enter the Book Id");
int bid3=s.nextInt();
String st = o.getCustomerWhoLoanedBook(bid3);
System.out.println("The Full name of customer who owned the book is"+st);
break;
case 4:
o.getTotalIssuedBookCount();
break;
}
}
// To loan a book by giving Bookid & Customer id
Boolean LoanBook(int cid,int bid){
for(Customer c: cl){
if(cid==c.getcusId()){
for(Book b : bl){
if(bid == b.getBookId() && b.getStatus() == "Available"){
if(c.count<5){
b.setstatus="loaned";
c.count++;
c.setcbid=b.bid;
return true;
}
}
return false;
}
}
return false;
}
return false;
}
// To Return a Book by giving Customer id & Book Id
boolean ReturnBook(int id2 , int bid2){
for(Customer c1: cl){
if(id2 == c1.getcusId()){
for(Book b1 : bl){
if(b1.getBookId()==c1.getcbid()){
b1.setstatus="Available";
c1.setcbid=0;
return true;
}
}
return false;
}
}
return false;
}
// To get the details of the person who owned the book
String getCustomerWhoLoanedBook(int bid){
for(Book b2:bl){
for(Customer c2: cl){
if(c2.cbid == b2.getBookId()){
String s=(c2.getfname()).concat(c2.getlname());
return s;
}
return "NILL";
}
}
return "NILL";
}
// to get the Count of total Issued Books
void getTotalIssuedBookCount(){
for(Customer c3: cl)
{
System.out.println("total Issued Book count is:" +c3.cbid);
}
}
}
}