Upload files to "OOP/Java/Lab/Week5"

This commit is contained in:
Aadit Agrawal 2024-09-02 02:51:28 +05:30
parent fe4d8de081
commit 0589cce66a
3 changed files with 36 additions and 12 deletions

View file

@ -1,6 +1,7 @@
import java.util.Scanner;
class Book {
String title, author;
int edition;
@ -11,11 +12,14 @@ class Book {
}
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: ");
@ -41,9 +45,19 @@ class Main {
String searchAuthor = sc.nextLine();
for (Book book : books) {
if (book.author.equals(searchAuthor)) {
if (book.author.equalsIgnoreCase(searchAuthor)) {
System.out.println(book);
return;
}
}
System.out.println("No books found for the author: " + searchAuthor);
if (!found) {
System.out.println(
"No books found for the author: " + searchAuthor
);
}
sc.close();
}
}