Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/ru/skypro/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.skypro;
//@AllArgsConstructor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не используем lombok пока, рано еще =)

//@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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хватает toString в обоих классах, тогда метод testString будет не нужен.

public String toString() {
return this.getFirstName() + ' ' + this.getLastName();
}
}
30 changes: 30 additions & 0 deletions src/ru/skypro/Book.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
9 changes: 8 additions & 1 deletion src/ru/skypro/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}