Update OOP/Java/Lab/Week5/Book.java
This commit is contained in:
parent
dcfe2c14e5
commit
b178260bf8
@ -1,9 +1,7 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class Book {
|
||||
|
||||
String title;
|
||||
String author;
|
||||
String title, author;
|
||||
int edition;
|
||||
|
||||
public Book(String title, String author, int edition) {
|
||||
@ -12,22 +10,12 @@ class Book {
|
||||
this.edition = edition;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"Title: %s, Author: %s, Edition: %d",
|
||||
title,
|
||||
author,
|
||||
edition
|
||||
);
|
||||
return String.format("Title: %s, Author: %s, Edition: %d", title, author, edition);
|
||||
}
|
||||
}
|
||||
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("Enter the number of books: ");
|
||||
@ -53,7 +41,7 @@ class Main {
|
||||
String searchAuthor = sc.nextLine();
|
||||
|
||||
for (Book book : books) {
|
||||
if (book.getAuthor().equals(searchAuthor)) {
|
||||
if (book.author.equals(searchAuthor)) {
|
||||
System.out.println(book);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user