0% found this document useful (0 votes)
5 views

Book Collections

Uploaded by

Lohith Seedella
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Book Collections

Uploaded by

Lohith Seedella
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Book{
int bookid;
String bookname;
String author;
double price;

public Book(int bookid, String bookname, String author, double price){


this.bookid=bookid;
this.bookname = bookname;
this.author=author;
this.price=price;
}

public String toString(){


return bookid+"\n"+bookname+"\n"+author+"\n"+price;
}
}

public class Solution {

public static List<Book> searchBookByAuthor(List<Book>list, String find){


List<Book>sa1 = new ArrayList<>();
for(Book b:list){
if(find.equalsIgnoreCase(b.author)){
sa1.add(b);
}
}
return sa1;
}

public static Book searchMinPriceBookInGivenRange(List<Book>list, double start,


double end){
double min = Integer.MAX_VALUE;
for(Book b:list){
if(b.price>start && b.price<end && b.price<min){
min=b.price;
}
}

List sa2 = new ArrayList<>();


for(Book b:list){
if(min==b.price){
return b;
}
}
return null;
}

public static void main(String args[]) throws Exception {


/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
List<Book> list = new ArrayList<>();
for(int i=0;i<n;i++){
int bookid = sc.nextInt();
sc.nextLine();
String bookname = sc.nextLine();
String author = sc.nextLine();
double price = sc.nextDouble();
list.add(new Book(bookid, bookname, author, price));
}
sc.nextLine();
String find = sc.nextLine();
double start = sc.nextDouble();
double end = sc.nextDouble();

List<Book> ans1 = searchBookByAuthor(list, find);

if(ans1.size()==0){
System.out.println("No book found with given author name");
}
else{
for(Book b:ans1){
System.out.println(b);
}
}

Book ans2 = searchMinPriceBookInGivenRange(list, start, end);


if(ans2==null){
System.out.println("No book found in the given price range");
}
else{
System.out.println(ans2);
}
}
}

You might also like