Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Name:Usama Sarwar Reg:45656

import java.util.Scanner;

public class Admin {


public String[] book;
private int nElems;

String[][] bookdetails;

String[][] addbook(){
int row,col,book,k;
Scanner input = new Scanner(System.in);
System.out.println("Enter rows");
row = input.nextInt();
System.out.println("Enter columns");
col = input.nextInt();
bookdetails = new String[row][col];

System.out.println("Enter Author Name");


for (int i = 0; i < bookdetails.length; i++) {
for (int j = 0; j < bookdetails.length; j++) {
System.out.print((i+j+i)+ " Book SNo. Author Name: ");
bookdetails[i][j] = input.next();
}}
return bookdetails;
}
public boolean searchbook(String searchKey)
{

int j;
for(j=0; j<nElems; j++)
if(book[j] == searchKey)

break;
if(j == nElems)
return false;
else
return true;
}

public boolean deletebook(String bookname)


{
int j;
for(j=0; j<nElems; j++)
if(bookname == book[j] )
break;
if(j==nElems)
return false;
else
{
for(int k=j; k<nElems; k++)
book[k] = book[k+1];
nElems--;
return true;
}
}
void bookdetails(String x[][]){

for (int i = 0; i < x.length; i++) {


for (int j = 0; j < x.length; j++) {
System.out.println("Book SNo."+(i+j+i) +" Author Name:"
+ x[i][j]);
}
}
}
}
import java.util.Scanner;

public class test {

public static void main(String[] args) {

Admin m = new Admin();

//Adding Books in library and Displaying it.


m.bookdetails(m.addbook());
String searchKey = "Admin";
if(m.searchbook(searchKey) )
System.out.println("Element that you search is "+ searchKey);
else
System.out.println("Element not Found at " + searchKey);
m.deletebook("Asim");
System.out.println("\nDelete Element");
}}

You might also like