From b178260bf8f3094c8c682990852ad205142c23a1 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Mon, 2 Sep 2024 01:24:23 +0530 Subject: [PATCH] Update OOP/Java/Lab/Week5/Book.java --- OOP/Java/Lab/Week5/Book.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/OOP/Java/Lab/Week5/Book.java b/OOP/Java/Lab/Week5/Book.java index fafdc57..462f32b 100644 --- a/OOP/Java/Lab/Week5/Book.java +++ b/OOP/Java/Lab/Week5/Book.java @@ -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); } }