java exercise4

 //implement a library using java class library

//methods: issuebook,returnbook,showavailablebooks
//properties:to store available books,store issued books
//exercise 4


package com.company;

class library {
String[] books;
int no_of_books;

library() {
this.books = new String[100];
this.no_of_books = 0;
}


void addbook(String book) {
this.books[no_of_books] = book;
no_of_books++;
System.out.println(book + ".... has been added.....");
}


void showavailablebooks() {
System.out.println("available books are :");
for (String book : this.books) {
if (book == null) {
//break;------//issue book jdi null hoye jy tale porer books shor krbe na tai continue
continue;
}
System.out.println("*..." + book);
}
}


void issuebook(String book) {

//for (String b:this.books){} -----------use korle i r value pabo na
for (int i = 0; i < this.books.length; i++) {
if (this.books[i].equals(book)) {
System.out.println("the book has been issued");
this.books[i] = null;
//String b =this.books[i];
return;
}
System.out.println("*..." + book);
}
System.out.println("this book does not exists");
}


void returnbook(String book) {
addbook(book);


}
}





public class cwh_chapter11_online_library {
public static void main(String[] args) {

library centrallibrary =new library();
centrallibrary.addbook("think and grow rich");
centrallibrary.addbook("big data book");
centrallibrary.addbook("mechine learning book");
centrallibrary.addbook("data science book");
centrallibrary.addbook("python book");
centrallibrary.addbook("data structure book");
centrallibrary.addbook("java programming book");
centrallibrary.addbook("c programming book");
centrallibrary.addbook("nonte fonte");
centrallibrary.addbook("gopal var");

centrallibrary.showavailablebooks();

centrallibrary.issuebook("python book");
centrallibrary.showavailablebooks();

centrallibrary.returnbook("python book");
centrallibrary.showavailablebooks();
}
}

Comments

Popular posts from this blog

java chapter11 practice question on abstruct class and interfaces

java practice set 8

new stored procidure with interval and frequery code