updated4classes

 avatar
unknown
java
2 years ago
3.8 kB
8
Indexable
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.util.ArrayList;

public class Library

{
    private static String name;
    private static String address;
    private static ArrayList<Book> books = new ArrayList<Book>();
    
    
	public static void main(String[] args) {
	    Library.books.add(new Book("A Thousand Plateus", "D&G", "Philosophy", "01323232-123123"));
	    
	    for(Book book : Library.books) {
	        System.out.println(book);
	    }
	}
}

/*-------------------------------------------- BOOK CLASS ----------------------------------------------*/

public class Book {
    private String title;
    private String author;
    private String genre;
    private String ISBN;
    
    
    public Book(String title, String author, String genre, String ISBN) {
        this.title = title;
        this.author = author;
        this.genre = genre;
        this.ISBN = ISBN;
    }
    
    public void setTitle(String title) {
            this.title = title;
        }
        
    public void setAuthor(String author) {
        this.author = author;
    }
    
    public void setGenre(String genre) {
        this.genre = genre;
    }
    
    public void setISBN(String ISBN) {
        this.ISBN = ISBN;
    }
    
    public String getTitle() {return this.title;}
    public String getAuthor() {return this.author;}
    public String getGenre() {return this.genre;}
    public String getISBN() {return this.ISBN;}
    
    @Override
    public String toString() {
        return "Title : " + "\t" + title + "\n" + "Author : " + "\t" + author + "\n" + "Genre : " + "\t" + genre + "\n" + "ISBN : " + "\t" + ISBN + "\n";
    }
    
}
/* ---------------------------------------------------------------- */
public class Librarian {
    private String name;
    private int id;
    
    public Librarian(String name, int id) {
        this.name = name;
        this.id = id;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    public void setID(int id) {
        this.id = id;
    }
    
    public String getName() {return this.name;}
    public int getId() {return this.id;}
    
    
    @Override
    public String toString() {
        return "Name: " + "\t" + name + "\n" + "ID: " + "\t" + id + "\n";
    }
}

/* -------------------------------------------- */


import java.util.ArrayList;


public class Member {
    private String name;
    private int id;
    private ArrayList<Book> borrowedBooks;
    
    
    public Member(String name, int id) {
        this. name = name;
        this. id = id;
        borrowedBooks = new ArrayList<Book>();
    }
    
    public void setName(String name) {this.name = name;}
    public void setID(int id) {this.id = id;}
    
    public void borrowBook(Book book) {
        borrowedBooks.add(book);
    }
    
    public ArrayList<Book> getBorrowedBooks() {
        return this.borrowedBooks;
    }
    public String getName(){return this.name;}
    public int getID() {return this.id;}
    
      @Override
    public String toString() {
        StringBuilder toreturn = new StringBuilder();
        
        toreturn.append("Name: ").append("\t").append(name).append("\n").append("ID: ").append("\t").append(id).append("\n");
        toreturn.append("\n").append("Borrowed Books: ");
        
        for (Book book : borrowedBooks) {
            toreturn.append("\n").append(book.getISBN());
        }
    
        toreturn.append("\n");
        return toreturn.toString();
    }
}
Editor is loading...
Leave a Comment