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
39 changes: 39 additions & 0 deletions src/ru/skypro/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.skypro;

import java.util.Objects;

//@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;
}
@Override
public String toString() {
return this.getFirstName() + ' ' + this.getLastName();
}
// Alt+Insert generated
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Author author = (Author) o;
return getFirstName().equals(author.getFirstName()) && getLastName().equals(author.getLastName());
}

@Override
public int hashCode() {
return Objects.hash(getFirstName(), getLastName());
}
}
48 changes: 48 additions & 0 deletions src/ru/skypro/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ru.skypro;

import java.util.Objects;

//@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;
}
@Override
public String toString() {
return this.getName() + " " + this.getAuthor() + ' ' + this.getPublicationYear();
}
// Alt+Insert generated
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Book book = (Book) o;
return getPublicationYear() == book.getPublicationYear() && getName().equals(book.getName()) && getAuthor().equals(book.getAuthor());
}

@Override
public int hashCode() {
return Objects.hash(getName(), getAuthor(), 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);
}
}