Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BookStore {
- Book[] books = new Book[10];
- int length=books.length;
- void sell(String bookTitle,int noOfCopies)
- {
- int i;
- for (i=0;i<length;i++)
- {
- if(books[i]==null)
- {
- break;
- }
- if(bookTitle.equals(books[i].bookTitle))
- {
- if(books[i].numOfCopies>noOfCopies)
- {
- books[i].numOfCopies-=noOfCopies;
- break;
- }
- else
- System.out.println("Number of copies is not available");
- }
- }
- }
- void order(String isbn,int noOfCopies)
- {
- int i,flag=0;
- for (i=0;i<length;i++)
- {
- if(books[i]==null)
- {
- flag=1;
- break;
- }
- if(isbn.equals(books[i].isbn))
- {
- books[i].numOfCopies+=noOfCopies;
- break;
- }
- if(flag==1)
- {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the author name: ");
- books[i]=new Book(isbn, isbn, isbn, noOfCopies);
- books[i].author=sc.nextLine();
- System.out.println("Enter the book title: ");
- books[i].bookTitle=sc.nextLine();
- books[i].isbn=isbn;
- books[i].numOfCopies=noOfCopies;
- }
- }
- }
- void display()
- {
- for(int i=0;i<10;i++)
- {
- if(books[i]==null)
- break;
- else
- System.out.println("Title: " + books[i].bookTitle + " Author: " + books[i].author + " ISBN: " + books[i].isbn + " Quantity: " + books[i].numOfCopies);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment