Skip to main content

TCS Xplore 2023 Ion Proctored Exam ( IPA) 9 - JAVA coding solution ( 35 marks )

      Problem Statement :

Create a class Resort and make attributes :

int resortID;

String resortName;

String category;

double rating;

double price;


Write  constructor and their getter and setter of all the attributes and make the attributes private .


Write a Solution class and a main method inside it. Inside main method , create a method avgPriceOfGivenCategory .

in this method you have to pass array object and one String input that will return integer value . we needs to check every object and if any object which has the category matched to string value taken by user and rating should be more than 4 then find then find the average price of the resorts .

 It returns the average price and print it  and if  returns 0 and print "No any resort" .

Input :

1001

abc resort

4 star

4.5

2000


1002

xyz resort

3 star

4.7

4000


1003

pqr resort

3 star

4.3

6000


1004

efg resort

3 star

4.9

5000

Code :

import java.util.*;

class Resort{
    int resortId;
    String resortName;
    String category;
    double rating;
    int price;

    public Resort(int resortId,String resortName,String category,double rating,int price){
        this.resortId=resortId;
        this.resortName=resortName;
        this.category=category;
        this.rating=rating;
        this.price=price;

    }

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

    Resort arr[]=new Resort[4];

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

        arr[i]=new Resort(a,b,c,d,e);
    }

    String str=sc.nextLine();
    int avg=avgPriceOfGivenCategory(arr,str);
    if(avg==0){
        System.out.println("NO resort found");
    }
    else{
        System.out.println(avg);
    }
 }
 public static int avgPriceOfGivenCategory(Resort arr[],String str){
    int sum=0,count=0;
   
    for(int i=0;i<arr.length;i++){
        if(arr[i].category.equalsIgnoreCase(str) && arr[i].rating>4){
            sum+=arr[i].price;
            count++;
        }
    }
    if(count==0){
        return 0;
    }
    else{
        return sum/count;
    }
 }
}

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 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) shoul

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