library management using Array list
package com.company;
import java.util.ArrayList;
//class Book{
// String bookName,authorName;
// public void set(String bookName,String authorName) {
// this.bookName = bookName;
// this.authorName = authorName;
// }
//}
class myLibrary{
public ArrayList<String> Books =new ArrayList<>();
public myLibrary(ArrayList<String> Books){
this.Books=Books;
}
public void addBook(String x){
this. Books.add(x);
System.out.println("Book has been added");
}
public void returnBook(String x){
this. Books.add(x);
System.out.println("Book has been added");
}
public void issueBook(int index,String issued_to,String issued_on){
this. Books.remove( index);
System.out.println("Book has been issued and issued to "+ issued_to +" and issued on "+issued_on);
}
public void showAvailableBooks(){
for (String e:Books) {
System.out.println(e);
}
}
}
public class CWH_104_Ex07 {
public static void main(String[] args) {
ArrayList<String> books= new ArrayList<>();
books.add("0.Mathematics 2 \n Author- Vicky kaushal");
books.add("1.Mathematics 1 \n Author- Romeo");
books.add("2.Mathematics 3 \n Author-Juliet");
books.add("3.chemistry 1 \n Author-Singh");
books.add("4.chemistry 2 \n Author-Hello world");
books.add("5.chemistry 3 \n Author- Pran");
books.add("6.physics 1 \n Author-Jenifer");
books.add("7.physics 2 \n Author-Gregorian");
books.add("8.physics 3 \n Author-Zebra singh");
books.add("9.Rich dad poor dad \n Author-Kittu pahalwaan");
myLibrary l= new myLibrary(books);
l.issueBook(3,"Rohan","26/08/2021");
l.showAvailableBooks();
}
}
Comments
Post a Comment