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

IPA32

Uploaded by

Aayush Agrawal
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)
9 views3 pages

IPA32

Uploaded by

Aayush Agrawal
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

import java.util.

*;

class TravelAgencies {
private int regNo;
private String agencyName;
private String pakageType;
private int price;
private boolean flightFacility;

public void setNo(int regNo) {


this.regNo = regNo;
}
public void setName(String agencyName) {
this.agencyName = agencyName;
}
public void setType(String pakageType) {
this.pakageType = pakageType;
}
public void setPrice(int price) {
this.price = price;
}
public void setFacility(boolean flightFacility) {
this.flightFacility = flightFacility;
}

public int getNo() {


return regNo;
}
public String getName() {
return agencyName;
}
public String getType() {
return pakageType;
}
public int getPrice() {
return price;
}
public boolean getFacility() {
return flightFacility;
}

public TravelAgencies(int regNo, String agencyName, String pakageType, int


price, boolean flightFacility)
{
this.regNo = regNo;
this.agencyName = agencyName;
this.pakageType = pakageType;
this.price = price;
this.flightFacility = flightFacility;
}
}
public class Main
{
public static int findAgencyWithHighestPackagePrice(TravelAgencies []ta)
{
int max = Integer.MIN_VALUE;
if(ta.length == 1)
{
return ta[0].getPrice();
}

for(int i=0;i<ta.length;i++)
{
if(ta[i].getPrice() > max)
{
max = ta[i].getPrice();
}
}
return max;
}

public static TravelAgencies[] agencyDetailsForGivenldAndType(TravelAgencies


[]ta, int target_no, String target_type)
{
boolean found = false;
ArrayList<TravelAgencies> list = new ArrayList<TravelAgencies>();
for(int i=0;i<ta.length;i++)
{
if(ta[i].getNo() == target_no &&
ta[i].getType().equalsIgnoreCase(target_type) && (ta[i].getFacility()))
{
found = true;
list.add(ta[i]);
}
}
TravelAgencies []result = new TravelAgencies[list.size()];
result = list.toArray(result);

if(found)
{
return result;
}
else
{
return null;
}

}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
TravelAgencies []ta = new TravelAgencies[n];

for(int i=0;i<n;i++)
{
int regNo = sc.nextInt();
sc.nextLine();
String agencyName = sc.nextLine();
String pakageType = sc.nextLine();
int price = sc.nextInt();
sc.nextLine();
boolean flightFacility = sc.nextBoolean();

ta[i] = new TravelAgencies(regNo, agencyName, pakageType, price,


flightFacility);

}
int target_no = sc.nextInt();
sc.nextLine();
String target_type = sc.nextLine();

int ans1 = findAgencyWithHighestPackagePrice(ta);

System.out.println(ans1);

TravelAgencies []ans2 = agencyDetailsForGivenldAndType(ta, target_no,


target_type);

if(ans2 != null)
{
for(int i=0;i<ans2.length;i++)
{
System.out.println(ans2[i].getName()+":"+ans2[i].getPrice());
}
}
else
{
System.out.println("No such agency found");
}
}
}

You might also like