0% found this document useful (0 votes)
7 views3 pages

Smartphone 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)
7 views3 pages

Smartphone 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/ 3

Smartphone collections

//Smartphone collections

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

class Smartphone{
int phoneid;
String brandname;
String rom;
double price;
public Smartphone(int phoneid, String brandname, String rom, double price){
this.phoneid=phoneid;
this.brandname=brandname;
this.rom=rom;
this.price=price;
}

public String toString(){


return phoneid +"\n"+brandname+"\n"+rom+"\n"+price;
}
}

public class Solution{

public static List<Smartphone> findPhoneByBrand(List<Smartphone>lists, String


find){

List<Smartphone> reslist = new ArrayList<>();

for(Smartphone x:lists)
{
if(find.equalsIgnoreCase(x.brandname))
{
reslist.add(x);
}
}
return reslist;
}

public static Smartphone findPhoneBetweenTwoRange(List<Smartphone>list2,


double low, double high)
{
double max=low;
for(Smartphone x:list2)
{
if(x.price>max && x.price<high)
{
max = x.price;
}
}

for(Smartphone y:list2)
{
if(y.price==max)
{
return y;
}
}
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<Smartphone> phonelist = new ArrayList<>();
for(int i=0;i<n;i++)
{
int pid=sc.nextInt();
sc.nextLine();
String bname=sc.nextLine();
String prom=sc.nextLine();
double pprice=sc.nextDouble();

phonelist.add(new Smartphone(pid,bname,prom,pprice));
}
sc.nextLine();
String findBrand = sc.nextLine();
double lo =sc.nextDouble();
double hi = sc.nextDouble();

List<Smartphone> ans1 = findPhoneByBrand(phonelist,findBrand);


if(ans1.size()==0)
{
System.out.println("No mobile with specific brand");
}
else{
for(Smartphone x:ans1){
System.out.println(x);
}
}

Smartphone ans2 = findPhoneBetweenTwoRange(phonelist, lo, hi);


if(ans2 == null)
{
System.out.println("No phones between those price ranges");
}else{
System.out.println(ans2.brandname);
System.out.println(ans2.rom);
System.out.println(ans2.price);
}
}
}

You might also like