ruhul0

BookStore

Feb 27th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BookStore {
  4.     Book[] books = new Book[10];
  5.     int length=books.length;
  6.     void sell(String bookTitle,int noOfCopies)
  7.     {
  8.         int i;
  9.         for (i=0;i<length;i++)
  10.         {
  11.             if(books[i]==null)
  12.             {
  13.                 break;
  14.             }
  15.                
  16.             if(bookTitle.equals(books[i].bookTitle))
  17.             {
  18.                 if(books[i].numOfCopies>noOfCopies)
  19.                 {
  20.                     books[i].numOfCopies-=noOfCopies;
  21.                     break;
  22.                 }
  23.                 else
  24.                     System.out.println("Number of copies is not available");
  25.                
  26.             }
  27.         }
  28.     }
  29.     void order(String isbn,int noOfCopies)
  30.     {
  31.         int i,flag=0;
  32.         for (i=0;i<length;i++)
  33.         {
  34.             if(books[i]==null)
  35.             {
  36.                 flag=1;
  37.                 break;
  38.             }
  39.             if(isbn.equals(books[i].isbn))
  40.             {
  41.                 books[i].numOfCopies+=noOfCopies;
  42.                 break;
  43.             }
  44.             if(flag==1)
  45.             {
  46.                 Scanner sc = new Scanner(System.in);
  47.                 System.out.println("Enter the author name: ");
  48.                 books[i]=new Book(isbn, isbn, isbn, noOfCopies);
  49.                 books[i].author=sc.nextLine();
  50.                 System.out.println("Enter the book title: ");
  51.                 books[i].bookTitle=sc.nextLine();
  52.                 books[i].isbn=isbn;
  53.                 books[i].numOfCopies=noOfCopies;
  54.             }
  55.            
  56.         }
  57.        
  58.     }
  59.     void display()
  60.     {
  61.         for(int i=0;i<10;i++)
  62.         {
  63.             if(books[i]==null)
  64.                 break;
  65.             else
  66.                 System.out.println("Title: " + books[i].bookTitle + " Author: " + books[i].author + " ISBN: " + books[i].isbn + " Quantity: " + books[i].numOfCopies);
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment