Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import java.util.*;
  2. class Book {
  3. int id;
  4. String name,author,publisher;
  5. int quantity;
  6. public Book(int id, String name, String author, String publisher, int quantity) {
  7. this.id = id;
  8. this.name = name;
  9. this.author = author;
  10. this.publisher = publisher;
  11. this.quantity = quantity;
  12. }
  13. }
  14. public class LinkedListExample {
  15. public static void main(String[] args) {
  16. //Creating list of Books
  17. List<Book> list=new LinkedList<Book>();
  18. //Creating Books
  19. Book b1=new Book(101,"Let us C","Yashwant Kanetkar","BPB",8);
  20. Book b2=new Book(102,"Data Communications & Networking","Forouzan","Mc Graw Hill",4);
  21. Book b3=new Book(103,"Operating System","Galvin","Wiley",6);
  22. //Adding Books to list
  23. list.add(b1);
  24. list.add(b2);
  25. list.add(b3);
  26. //Traversing list
  27. for(Book b:list){
  28. System.out.println(b.id+" "+b.name+" "+b.author+" "+b.publisher+" "+b.quantity);
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement