Join https://t.me/Tcsexplores for productive discussions on TCS Xplore and joining in 2021.
Previous year coding questions and solutions : https://github.com/topics/tcs-xplore
IPA coding questions of Python :
(26th Jan)
1st question of 15 marks was :
Take an integer as input . Calculate the sum of its digit . If the sum is divisible by 3 , then print True , else print False .
2nd question of 35 marks was :
Create a class pan . Make attributes id , material , brand , price and capacity .
Write getters , setters and constructor having argument in same order as above .
Write the solution class and write main method , implement two static functions namely (costliest pan) and (discounted price) in it.
Costliest pan function : It accepts 2 arguments , namely the array of pan class objects and material of a pan . It return the costliest pan of the given material .
Discounted price : It accepts 2 arguments , namely , array of pan objects and brand of pan .
If capacity of given brand > 500 ml , update price to 20% discount .
If capacity > 1000 ml , then update price to 26% discount .
In the main function , take input of variable for 4 class objects .
Take material as input , then take brand as input for passing to different functions.
Call the costliest pan function , print the id of the object returned.
Call the discounted price function , print the new value after updating .
For solutions to these questions and more details on tcs-nqt/xplore/joining process , join : https://t.me/Tcsexplores
OPA question of Java :


Code :
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TravelAgencies[] ta = new TravelAgencies[4];
for (int i = 0; i < ta.length; i++) {
int regNo = sc.nextInt();
sc.nextLine();
String agencyName = sc.nextLine();
String packageType = sc.nextLine();
int price = sc.nextInt();
boolean flightFacility = sc.nextBoolean();
ta[i] = new TravelAgencies(regNo, agencyName, packageType, price, flightFacility);
}
int getRegNo = sc.nextInt();
sc.nextLine();
String getPackageType = sc.nextLine();
sc.close();
int highestPackagePrice = findAgencyWithHighestPackagePrice(ta);
TravelAgencies travelAgencies = agencyDetailsForGivenIdAndType(ta, getRegNo, getPackageType);
System.out.println(highestPackagePrice);
if (travelAgencies == null)
System.out.println("A string value should be printed here!");
else
System.out.println(travelAgencies.getAgencyName() + ":" + travelAgencies.getPrice());
}
public static int findAgencyWithHighestPackagePrice(TravelAgencies[] agencies) {
int maxPrice = agencies[0].getPrice();
for (int i = 1; i < agencies.length; i++) {
if (agencies[i].getPrice() > maxPrice)
maxPrice = agencies[i].getPrice();
}
return maxPrice;
}
public static TravelAgencies agencyDetailsForGivenIdAndType(TravelAgencies[] agencies, int regNo, String packageType) {
for (int i = 0; i < agencies.length; i++) {
if (agencies[i].getFlightFacility()) {
if (agencies[i].getRegNo() == regNo && packageType.equalsIgnoreCase(agencies[i].getPackageType())) {
return agencies[i];
}
}
}
return null;
}
}
class TravelAgencies {
int regNo;
String agencyName;
String packageType;
int price;
boolean flightFacility;
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;
}
}