forked from learning-zone/java-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComposition.java
More file actions
47 lines (37 loc) · 1008 Bytes
/
Composition.java
File metadata and controls
47 lines (37 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package oopsconcepts;
import java.util.ArrayList;
import java.util.List;
class Book {
public String title;
public String author;
Book(String title, String author) {
this.title = title;
this.author = author;
}
}
class Library {
private final List<Book> books;
Library(List<Book> books){
this.books = books;
}
public List<Book> getTotalBooksInLibrary() {
return books;
}
}
public class Composition {
public static void main(String[] args) {
Book b1 = new Book("Effective Java", "Joshua Bloch");
Book b2 = new Book("Thinking in Java", "Bruce Eckel");
Book b3 = new Book("Java: The Complete Reference", "Herbet Schildt");
// Creating the list which contains the no of books.
List<Book> books = new ArrayList<Book>();
books.add(b1);
books.add(b2);
books.add(b3);
Library library = new Library(books);
List<Book> bks = library.getTotalBooksInLibrary();
for(Book bk: bks) {
System.out.println("Title: "+bk.title + " and "+ "Author: "+bk.author);
}
}
}