Skip to main content

TCS IPA previous year quistion ( 35 marks ) , Quistion , Input , output

 Problem Statement




Video Link :   https://youtu.be/XCBvfJAo908

Create a class TravelAgencies with below attributes:

regNo – int

agencyName – String

pakageType – String

price – int

flightFacility – boolean


Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence.


Create class Solution with main method. Implement two static methods – findAgencyWithHighestPackagePrice and agencyDetailsforGivenIdAndType in Solution class.


findAgencyWithHighestPackagePrice method:


This method will take array of TravelAgencies objects as an input parameter and return the highest package price from the given array of objects.


agencyDetailsForGivenldAndType method:


This method will take three input parameters -array of TravelAgencies objects, int parameter regNo and String parameter packageType. The method will return the TravelAgencies object based on below conditions.


FlightFacility should be available.

The input parameters(regNo and packageType) should matched with the regNo and packageType of TravelAgencies object.

If any of the above conditions are not met, then the method should return null. Note : Same Travel agency can have more than one package type. Travel agency and package type combination is unique. All the searches should be case insensitive.


The above mentioned static methods should be called from the main method.



For findAgencyWithHighestPackagePrice method – The main method should print the highestPackagePrice as it is. For agencyDetailsForGivenldAndType method -The main method should print the AgencyName and price of the returned object.The AgencyName and price should be concatinated with : while printing.


Input

123

A2Z Agency

Platinum

50000

true

345

SSS Agency

Gold

30000

false

987

Cox and Kings

Diamond

40000

true

888

Global Tours

Silver

20000

false

987

Diamond

Output

50000

Cox and Kings:40000 



Code ( In java )


import java.util.*;
class TravelAgencies{
    int regNo;
    String agencyName;
    String packageType;
    int price;
    boolean flightFacility;

    public TravelAgencies(int regNo, String agencyName , String packageType , int price, boolean flightFacility){
        this.regNo=regNo;
        this.agencyName = agencyName;
        this.packageType = packageType;
        this.price = price;
        this.flightFacility = flightFacility;
    }

    int getRegNo(){
        return regNo;
    }
    String getAgencyName() {
        return agencyName;
    }
    String getPackageType() {
        return packageType;
    }
    int getPrice() {
        return price;
    }
    boolean getFlightFacility() {
        return flightFacility;
    }
}
public class Solution{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        TravelAgencies arr[]=new TravelAgencies[4];

        for(int i=0;i<arr.length;i++){
            int a=sc.nextInt();
            sc.nextLine();
            String b=sc.nextLine();
            String c=sc.nextLine();
            int d=sc.nextInt();
            boolean e=sc.nextBoolean();

            arr[i]=new TravelAgencies(a, b, c, d, e) ;          
        }
        int maxPrice=findAgencyWithHighestPackagePrice(arr);
       
        int inputRegNo=sc.nextInt();
        sc.nextLine();
        String inputPackageType=sc.nextLine();

        TravelAgencies obj =agencyDetailsForGivenldAndType(arr,inputRegNo,inputPackageType);

        System.out.println(maxPrice);
        if(obj == null){
            System.out.println("not Found");
        }
        else{
            System.out.println(obj.agencyName+":"+obj.price);
        }

    }
    public static int findAgencyWithHighestPackagePrice(TravelAgencies arr[]){
        int maxx=arr[0].price;
        for(int i=0;i<4;i++){
            if(arr[i].price>maxx){
                maxx=arr[i].price;
            }
        }
        return maxx;
    }
    public static TravelAgencies agencyDetailsForGivenldAndType(TravelAgencies arr[],int inputRegNo,String inputPackageType){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].flightFacility==true) {
                if (arr[i].regNo == inputRegNo && inputPackageType.equalsIgnoreCase(arr[i].getPackageType())) {
                    return arr[i];
                }
            }
        }
        return null;
    }
}

Comments

Popular posts from this blog

Complete Strategy to clear TCS Xplore IPA in One Attempt Now ( 80+ Score )

  So hello Everyone , Here are the all Links from where you can Practice !  All the resources are searched from my best !  1. For KYT and Bizzskill  Link :- tcs Xplore course  2. Unix Operating system Link :-    a.  click here Link 1 b.  click here Link 2 c.  Click here Link 3   3. UI  Link :-  click here 4. SQL and Pl SQL Link : -  Click here Click here click here 5. Java MCQ  Link :-  click here click here click here 6. Java coding :-  Access the playlist on YouTube :-  click here to watch Access the blogs :-  click here All in one link :-   click here

TCS IPA previous year problems solved [input + output ] in JAVA - (35 marks )

  Problem Statement :  Video Link :   Click Here Create a class AutonomousCar with the below attributes: carld – int brand – String   noOfTestsConducted – int noOfTestsPassed- int environment – String grade – String Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence except grade. Create class Solution with main method. Implement two static methods – findTestPassedByEnv and updateCarGrade in Solution class. findTestPassedByEnv method: This method will take two input parameters -array of AutonomousCar objects and string parameter environment. The method will return the sum of the noOfTestsPassed attribute from autonomousCar objects for the environment passed as parameter. If no autonomousCar with the given environment is present in the array of AutonomousCar objects, then the method should return 0. updateCarGrade method: This method will take a String parameter brand, along with the array of AutonomousCar objects. The method