Guest User

Untitled

a guest
Jun 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. public class Book {
  2.  
  3. private String bookTitle;
  4. private String bookAuthor;
  5. private String bookISBN;
  6. private int bookCopies;
  7.  
  8. Book()
  9. {
  10. this("null","null","null",0);
  11. }
  12. Book(String bookTitle,String bookAuthor, String bookISBN, int bookCopies)
  13. {
  14. this.bookTitle=bookTitle;
  15. this.bookAuthor=bookAuthor;
  16. this.bookISBN=bookISBN;
  17. this.bookCopies=bookCopies;
  18. }
  19.  
  20. public String getBookTitle() {
  21. return bookTitle;
  22. }
  23. public void setBookTitle(String bookTitle) {
  24. this.bookTitle = bookTitle;
  25. }
  26. public String getBookAuthor() {
  27. return bookAuthor;
  28. }
  29. public void setBookAuthor(String bookAuthor) {
  30. this.bookAuthor = bookAuthor;
  31. }
  32. public String getBookISBN() {
  33. return bookISBN;
  34. }
  35. public void setBookISBN(String bookISBN) {
  36. this.bookISBN = bookISBN;
  37. }
  38. public int getBookCopies() {
  39. return bookCopies;
  40. }
  41. public void setBookCopies(int bookCopies) {
  42. this.bookCopies = bookCopies;
  43. }
  44. public void display()
  45. {
  46. System.out.println("Book title is :"+ bookTitle);
  47. System.out.println("Book author is :"+ bookAuthor);
  48. System.out.println("Book ISBN is :"+ bookISBN);
  49. System.out.println("No. of copies are :"+ bookCopies);
  50. }
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. -----------------------------------------------------------------------------
  58.  
  59.  
  60. //import java.util.Scanner;
  61. import java.util.Scanner;
  62.  
  63. public class BookStore {
  64. int totalBooks;
  65. String Title,Author,ISBN;
  66. int Copies;
  67.  
  68. Book[] books;
  69. public void initialise()
  70. {
  71. Scanner r=new Scanner(System.in);
  72. System.out.println("enter total no. of books you want to enter");
  73. totalBooks = r.nextInt();
  74. books = new Book[totalBooks];
  75. for(int i=0;i<totalBooks;i++)
  76. {
  77. System.out.println("enter title");
  78. Title = r.next();
  79. System.out.println("enter author");
  80. Author = r.next();
  81. System.out.println("enter isbn");
  82. ISBN = r.next();
  83. System.out.println("enter copies");
  84. Copies = r.nextInt();
  85. books[i]=new Book(Title,Author,ISBN,Copies);
  86. }
  87. //r.close();
  88. }
  89. public void sell(String Title, int Copies)
  90. {
  91. for(int i=0;i<totalBooks;i++)
  92. {
  93. if((books[i].getBookTitle().equals(Title))&&(books[i].getBookCopies()>=Copies))
  94. {
  95. books[i].setBookCopies(books[i].getBookCopies()-Copies);
  96. break;
  97.  
  98. }
  99. else
  100. {
  101. System.out.println("Book not found !!");
  102. }
  103. }
  104. }
  105.  
  106. public void order(String isbn, int Copies)
  107. {
  108. for(int i=0;i<1;i++)
  109. {
  110. if((books[i].getBookISBN().equals(isbn)))
  111. {
  112. books[i].setBookCopies(books[i].getBookCopies()+Copies);
  113. //totalBooks++;
  114. display();
  115. //break;
  116. }
  117. else
  118. {
  119. i++;
  120. Scanner r2=new Scanner(System.in);
  121. System.out.println("enter title \n");
  122. Title=r2.nextLine();
  123. System.out.println("enter author \n");
  124. Author=r2.nextLine();
  125. System.out.println("enter isbn \n");
  126. ISBN=r2.nextLine();
  127. //System.out.println("enter copies \n");
  128. //Copies=r2.nextInt();
  129. books[i]=new Book(Title,Author,ISBN,Copies);
  130. totalBooks++;
  131. display();
  132. r2.close();
  133. }
  134. }
  135. }
  136. public void display()
  137. {
  138. //Scanner r=new Scanner(System.in);
  139. for(int j=0;j<totalBooks;j++)
  140. {
  141. System.out.println("Book title is "+ books[j].getBookTitle());
  142. System.out.println("enter author " + books[j].getBookAuthor());
  143. System.out.println("enter isbn" + books[j].getBookISBN());
  144. System.out.println("enter copies" + books[j].getBookCopies());
  145. }
  146. }
  147. }
  148.  
  149. -----------------------------------------------------------------------------
  150.  
  151.  
  152. import java.util.Scanner;
  153.  
  154. public class BookStoreApp {
  155.  
  156. public static void main(String args[])
  157. {
  158. BookStore book=new BookStore();
  159. book.initialise();
  160. Scanner scan=new Scanner(System.in);
  161. System.out.println("Enter option: 1." + '\n' + "to display all the books" + '\n' + "2.to order the books" +'\n'+ "3. sell the books");
  162.  
  163. int choice= scan.nextInt();
  164. //System.out.println(choice);
  165. switch(choice)
  166. {
  167. case 1:
  168. book.display();
  169. break;
  170. case 2:
  171. book.order("abc", 100);
  172. break;
  173. case 3:
  174. book.sell("Race 3", 50);
  175. break;
  176. case 0:
  177. System.exit(0);
  178. break;
  179. default:
  180. System.out.println(" Go get some life !!");
  181.  
  182. }
  183. scan.close();
  184.  
  185.  
  186.  
  187.  
  188. }
  189.  
  190. }
Add Comment
Please, Sign In to add comment