Skip to content

Instantly share code, notes, and snippets.

@Yurlov
Created June 30, 2016 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yurlov/2defd1b7b3a624dcdc3d56196bf5c832 to your computer and use it in GitHub Desktop.
Save Yurlov/2defd1b7b3a624dcdc3d56196bf5c832 to your computer and use it in GitHub Desktop.
Prog.kiev.ua
public class Book {
private int id;
private String name;
private String author;
private int year;
private int pages;
private int price;
private String publishing;
private String bindingType;
public String getAuthor() {
return author;
}
public Book setAuthor(String author) {
this.author = author;
return this;
}
public String getBindingType() {
return bindingType;
}
public void setBindingType(String bindingType) {
this.bindingType = bindingType;
}
public String getPublishing() {
return publishing;
}
public Book setPublishing(String publishing) {
this.publishing = publishing;
return this;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public int getYear() {
return year;
}
public Book setYear(int year) {
this.year = year;
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public Book setId(int id) {
this.id = id;
return this;
}
@Override
public String toString(){
return "[ Author: "+author+" Publishing: "+publishing+" Year: "+ year+" ]";
}
}
public class BookRunner {
public static void main(String[] args) {
List<Book> books = createBooks();
getAuthor(books, "John Smith");
getPublishing(books, "Epolet");
getYear(books, 1999);
}
private static void getYear(List<Book> books, int year) {
for (Book o : books
) {
if (o.getYear() > year) {
System.out.println(o.toString());
}
}
}
private static List<Book> createBooks() {
List<Book> books = new ArrayList<>();
books.add(new Book()
.setAuthor("John Smith")
.setYear(2010)
.setPublishing("Terra Incognita"));
books.add(new Book()
.setAuthor("Martin Slizerin")
.setYear(2001)
.setPublishing("Epolet"));
books.add(new Book()
.setAuthor("John Smith")
.setYear(1998)
.setPublishing("Monolith"));
books.add(new Book()
.setAuthor("William Stern")
.setYear(1984)
.setPublishing("Epolet")
);
return books;
}
private static void getPublishing(List<Book> books, String publishing) {
for (Book o : books
) {
if (o.getPublishing().equals(publishing))
System.out.println(o.toString());
}
}
private static void getAuthor(List<Book> books, String author) {
for (Book o : books) {
if (o.getAuthor().equals(author)) {
System.out.println(o.toString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment