Advertisement
Saleh_Zoabi

libraryzeev

Dec 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package Cls;
  2.  
  3. public class library implements AddBookable { // ספריה שמכילה מערך של ספרים שונים
  4.     private String[] allBooks;
  5.  
  6.     public library(String[] allBooks)
  7.     {
  8.         this.allBooks=allBooks;
  9.     }
  10.    
  11.     public void AddBook(String[] allBooks, String bookName) {
  12.        
  13.         int w = allBooks.length;
  14.         String[] Temp = new String[w + 1];
  15.  
  16.         for (int i = 0; i < Temp.length-1; i++) {
  17.  
  18.             Temp[i] = allBooks[i];
  19.  
  20.         }
  21.  
  22.         Temp[Temp.length-1] = bookName;
  23.         this.allBooks=Temp;
  24.     }
  25.    
  26.     public String[] getAllBooks()
  27.     {
  28.         return this.allBooks;
  29.     }
  30.  
  31.     @Override
  32.     public String[] loanBook(String[] library, String bookName) {
  33.         // TODO Auto-generated method stub
  34.         return null;
  35.     }
  36. }
  37.  
  38. ===========================================
  39. package Main;
  40.  
  41. import java.util.Scanner;
  42.  
  43. import Cls.Lecturer;
  44. import Cls.Student;
  45. import Cls.library;
  46. public class Tester {
  47.  
  48.     public static void main(String[] args) {
  49.  
  50.         // TODO Auto-generated method stub
  51.  
  52.         String[] allBooks = { "Secret", "Bora Bora", "On The Beach", "Moon" }; // הגדרת מערך בעל 4 ספרים
  53.         Object[] allSubscribers = new Object[4]; // מערך בעל 4 אנשים
  54.        
  55.  
  56.         allSubscribers[0] = new Student("Bilal", 4.5);
  57.         allSubscribers[1] = new Lecturer("Catrina");
  58.         allSubscribers[2] = new Student("Joul", 9.5);
  59.         allSubscribers[3] = new Lecturer("Maria");
  60.        
  61.  
  62.        
  63.         ((Lecturer) allSubscribers[1]).loanBook(allBooks, "Moon"); // שהמרצה הרשאון ישאיל את ספר הירח
  64.        
  65.         System.out.println();
  66.    
  67.        
  68.         ((Student) allSubscribers[0]).loanBook(allBooks, "Moon"); // שהסטודנט הראשון ישאיל את אותו הספר
  69.        
  70.         System.out.println();
  71.        
  72.         for (int i = 0; i < allBooks.length; i++) { // תדפיס לי  את מערך הספרים עכשיו
  73.             System.out.println(allBooks[i]);
  74.         }
  75.  
  76.         System.out.println();
  77.         ((Lecturer) allSubscribers[3]).returnBook(allBooks, "Moon"); // שהמרצה השלישי יחזיר את ספר הירח
  78.  
  79.         System.out.println();
  80.        
  81.         for (int i = 0; i < allBooks.length; i++) { // תדפיס לי את המערך אחרי ההחזרה
  82.             System.out.println(allBooks[i]);
  83.         }
  84.         library lib = new library(allBooks) ;
  85.         lib.AddBook(allBooks,"Zeevik the fox");
  86.         allBooks=lib.getAllBooks();
  87.         for (String item:allBooks)
  88.         {
  89.             System.out.println(item);
  90.         }
  91.     }
  92.    
  93. }
  94. =====================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement