Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Cls;
- public class library implements AddBookable { // ספריה שמכילה מערך של ספרים שונים
- private String[] allBooks;
- public library(String[] allBooks)
- {
- this.allBooks=allBooks;
- }
- public void AddBook(String[] allBooks, String bookName) {
- int w = allBooks.length;
- String[] Temp = new String[w + 1];
- for (int i = 0; i < Temp.length-1; i++) {
- Temp[i] = allBooks[i];
- }
- Temp[Temp.length-1] = bookName;
- this.allBooks=Temp;
- }
- public String[] getAllBooks()
- {
- return this.allBooks;
- }
- @Override
- public String[] loanBook(String[] library, String bookName) {
- // TODO Auto-generated method stub
- return null;
- }
- }
- ===========================================
- package Main;
- import java.util.Scanner;
- import Cls.Lecturer;
- import Cls.Student;
- import Cls.library;
- public class Tester {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String[] allBooks = { "Secret", "Bora Bora", "On The Beach", "Moon" }; // הגדרת מערך בעל 4 ספרים
- Object[] allSubscribers = new Object[4]; // מערך בעל 4 אנשים
- allSubscribers[0] = new Student("Bilal", 4.5);
- allSubscribers[1] = new Lecturer("Catrina");
- allSubscribers[2] = new Student("Joul", 9.5);
- allSubscribers[3] = new Lecturer("Maria");
- ((Lecturer) allSubscribers[1]).loanBook(allBooks, "Moon"); // שהמרצה הרשאון ישאיל את ספר הירח
- System.out.println();
- ((Student) allSubscribers[0]).loanBook(allBooks, "Moon"); // שהסטודנט הראשון ישאיל את אותו הספר
- System.out.println();
- for (int i = 0; i < allBooks.length; i++) { // תדפיס לי את מערך הספרים עכשיו
- System.out.println(allBooks[i]);
- }
- System.out.println();
- ((Lecturer) allSubscribers[3]).returnBook(allBooks, "Moon"); // שהמרצה השלישי יחזיר את ספר הירח
- System.out.println();
- for (int i = 0; i < allBooks.length; i++) { // תדפיס לי את המערך אחרי ההחזרה
- System.out.println(allBooks[i]);
- }
- library lib = new library(allBooks) ;
- lib.AddBook(allBooks,"Zeevik the fox");
- allBooks=lib.getAllBooks();
- for (String item:allBooks)
- {
- System.out.println(item);
- }
- }
- }
- =====================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement