Created
August 19, 2015 09:12
-
-
Save yaswanthrajyadiki/83595812960ca25ea724 to your computer and use it in GitHub Desktop.
Book shelf problem using basics in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Write a description of class Bookshelf here. | |
* | |
* @author (Yaswanth) | |
* @version (09-08-2015) | |
*/ | |
public class Bookshelf | |
{ | |
private String bookName; | |
private int noOfBooks; | |
private String listOfBooks; | |
Bookshelf() | |
{ | |
bookName=""; | |
listOfBooks=""; | |
noOfBooks=0; | |
System.out.println("Bookshelf is created"); | |
} | |
public void addBook(String name) | |
{ | |
listOfBooks = listOfBooks+name+","; | |
noOfBooks=noOfBooks+1; | |
} | |
public void removeBook(String name) | |
{ | |
listOfBooks = listOfBooks.replace(name+",",""); | |
noOfBooks=noOfBooks-1; | |
} | |
public void searchBook(String name) | |
{ | |
if(this.listOfBooks.indexOf(name)>0) | |
{ | |
System.out.println("Book is present in shelf"); | |
} | |
else | |
{ | |
System.out.println("Book is not present in shelf"); | |
} | |
} | |
public String getAllBooks() | |
{ System.out.println("Number of books in shelf: "+noOfBooks); | |
System.out.print("List of books: "); | |
return listOfBooks; | |
} | |
public static void main(String args[]) | |
{ | |
Bookshelf bs=new Bookshelf(); | |
bs.addBook("LetUsC"); | |
bs.addBook("ThinkJava"); | |
bs.removeBook("LetUsC"); | |
bs.addBook("DataStructures"); | |
bs.searchBook("LetUsC"); | |
System.out.println(bs.getAllBooks()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment