diff --git a/src/ru/skypro/Author.java b/src/ru/skypro/Author.java new file mode 100644 index 0000000..eb85c83 --- /dev/null +++ b/src/ru/skypro/Author.java @@ -0,0 +1,22 @@ +package ru.skypro; +//@AllArgsConstructor +//@Getter +public class Author { + private String firstName; + private String lastName; + + public Author(final String firstName,final String lastName) { + this.firstName=firstName; + this.lastName=lastName; + } + + public String getFirstName(){ + return this.firstName; + } + public String getLastName(){ + return this.lastName; + } + public String toString() { + return this.getFirstName() + ' ' + this.getLastName(); + } +} diff --git a/src/ru/skypro/Book.java b/src/ru/skypro/Book.java new file mode 100644 index 0000000..f6292d8 --- /dev/null +++ b/src/ru/skypro/Book.java @@ -0,0 +1,30 @@ +package ru.skypro; +//@AllArgsConstructor +//@Getter +public class Book { + private String name; + private Author author; + //@Setter + private int publicationYear; + + public Book(final String name,final Author author,final int publicationYear) { + this.name=name; + this.publicationYear=publicationYear; + this.author=author; + } + public String getName() { + return this.name; + } + public Author getAuthor() { + return this.author; + } + public int getPublicationYear() { + return this.publicationYear; + } + public void setPublicationYear(final int publicationYear) { + this.publicationYear = publicationYear; + } + public String toString() { + return this.getName() + " " + this.getAuthor() + ' ' + this.getPublicationYear(); + } +} diff --git a/src/ru/skypro/Main.java b/src/ru/skypro/Main.java index 625884e..664541c 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -1,7 +1,14 @@ package ru.skypro; public class Main { - public static void main(String[] args){ + public static void main(String[] args){ + var author1 = new Author("Ivan","Ivanov"); + var author2 = new Author("Петя","Петров"); + var book1 = new Book("ivanovskaya",author1,2013); + var book2 = new Book("Петровская книга",author1,1999); + book2.setPublicationYear(2015); + System.out.println(book1); + System.out.println(book2); } }