0% found this document useful (0 votes)
81 views11 pages

PRA Mock

Uploaded by

arghya.som
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views11 pages

PRA Mock

Uploaded by

arghya.som
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Link: https://hr.

gs/ilp1stfebsbq2

<Customer Question>

Code:

import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;

public class Solution {

public static void main(String args[] ) throws Exception {

Scanner scan = new Scanner(System.in);

int number = scan.nextInt(); scan.nextLine();

Customer[] cust = new Customer[number];

for (int i = 0; i < cust.length; i++) {

int id = scan.nextInt(); scan.nextLine();

String name = scan.nextLine();

double salary = scan.nextDouble(); scan.nextLine();

int age = scan.nextInt(); scan.nextLine();

cust[i] = new Customer(id, name, salary, age);

double average = findAvgSal(cust);

double searchSal = scan.nextDouble();

if(average>0){

System.out.println("Average of salary "+average);

Customer answer = searchCustBySal(cust,searchSal);

if(answer!=null){

System.out.println("id-"+answer.getId());

System.out.println("name-"+answer.getName());

System.out.println("salary-"+answer.getSalary());

System.out.println("age-"+answer.getAge());
}

else{

System.out.println("No Customer found with mentioned attribute");

public static double findAvgSal(Customer[] cust){

double sum =0;

int flag =0;

int number = cust.length;

for (int i = 0; i < cust.length; i++) {

sum = sum+cust[i].getSalary();

flag =1;

if(flag == 1)

return (double) sum/number;

else

return 0;

public static Customer searchCustBySal(Customer[] cust, double searchSal){

Customer dummy = null;

for (int i = 0; i < cust.length; i++) {

if(cust[i].getSalary() == searchSal){

dummy = cust[i];

return dummy;

class Customer{

private int id;

private String name;

private double salary;


private int age;

public Customer(int id,String name,double salary,int age){

this.id = id;

this.name = name;

this.salary = salary;

this.age = age;

public int getId() {

return id;

public String getName() {

return name;

public double getSalary() {

return salary;

public int getAge() {

return age;

}
Link: https://hr.gs/ilp1stfebsbq3

<Training Room Question>

Code:

import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;

public class Solution {

public static void main(String args[] ) throws Exception {

Scanner scan = new Scanner(System.in);

TrainingRoom[] tr = new TrainingRoom[4];

for (int i = 0; i < tr.length; i++) {

int trainingRoomid = scan.nextInt();scan.nextLine();

int trainingRoomSystemsCount = scan.nextInt();scan.nextLine();

String businessGroup = scan.nextLine();

int activeSystems = scan.nextInt();scan.nextLine();

int faultySystems = scan.nextInt();scan.nextLine();

String projectorStatus = scan.nextLine();

int desktopsCount = scan.nextInt();scan.nextLine();

int thinClientsCount = scan.nextInt();scan.nextLine();

tr[i] = new TrainingRoom(trainingRoomid, trainingRoomSystemsCount, businessGroup, activeSystems,


faultySystems, projectorStatus, desktopsCount, thinClientsCount);

String bizGrp = scan.nextLine();

String prStatus = scan.nextLine();

double average = findAvgTrSysBiz(tr,bizGrp);

if(average>=0){

System.out.println(average);

else

System.out.println("TrainingRoom not allotted under specific BusinessGroup");


TrainingRoom answer = fTrMaxAcWithPrStat(tr,prStatus);

if(answer!=null){

System.out.println(answer.getTrainingRoomid());

System.out.println(answer.getTrainingRoomSystemsCount());

else

System.out.println("No TrainingRooms present with the specific projector status");

public static TrainingRoom fTrMaxAcWithPrStat(TrainingRoom[] tr, String prStatus){

TrainingRoom dummy = null;

int max = Integer.MIN_VALUE;

for (int i = 0; i < tr.length; i++) {

if((tr[i].getProjectorStatus().equalsIgnoreCase(prStatus)) && (tr[i].getActiveSystems()>max)){

max = tr[i].getActiveSystems();

dummy = tr[i];

return dummy;

public static double findAvgTrSysBiz(TrainingRoom[] tr,String bizGrp){

int sum =0;

int count =0;

for (int i = 0; i < tr.length; i++) {

if(tr[i].getBusinessGroup().equalsIgnoreCase(bizGrp)){

sum = sum+tr[i].getTrainingRoomSystemsCount();

count++;

if(count>0){
return (double) sum/count;

else

return -1;

class TrainingRoom{

private int trainingRoomid;

private int trainingRoomSystemsCount;

private String businessGroup;

private int activeSystems;

private int faultySystems;

private String projectorStatus;

private int desktopsCount;

private int thinClientsCount;

public TrainingRoom( int trainingRoomid,int trainingRoomSystemsCount,String businessGroup,int


activeSystems,int faultySystems,String projectorStatus,int desktopsCount,int thinClientsCount){

this.trainingRoomid = trainingRoomid;

this.trainingRoomSystemsCount = trainingRoomSystemsCount;

this.businessGroup = businessGroup;

this.activeSystems = activeSystems;

this.activeSystems = activeSystems;

this.faultySystems = faultySystems;

this.projectorStatus = projectorStatus;

this.desktopsCount = desktopsCount;

this.thinClientsCount = thinClientsCount;

public int getTrainingRoomid() {

return trainingRoomid;

}
public int getTrainingRoomSystemsCount() {

return trainingRoomSystemsCount;

public String getBusinessGroup() {

return businessGroup;

public int getActiveSystems() {

return activeSystems;

public int getFaultySystems() {

return faultySystems;

public String getProjectorStatus() {

return projectorStatus;

public int getDesktopsCount() {

return desktopsCount;

public int getThinClientsCount() {

return thinClientsCount;

}
Link: https://hr.gs/ilp1stfebsbq4

<Staff Question>

Code:

import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;

public class Solution {

public static void main(String args[]) throws Exception {

Scanner scan = new Scanner(System.in);

Staff[] stf = new Staff[4];

for (int i = 0; i < stf.length; i++) {

int staffId = scan.nextInt(); scan.nextLine();

String staffName = scan.nextLine();

String deptName = scan.nextLine();

float yearsOfExperience = scan.nextFloat(); scan.nextLine();

double currentSalary = scan.nextDouble();scan.nextLine();

stf[i] = new Staff(staffId, staffName, deptName, yearsOfExperience, currentSalary);

String departName = scan.nextLine();

double average = findAvgSalForDept(stf,departName);

if(average>=0){

System.out.println(average);

else

System.out.println("Department doesn't exist");


Staff answer = findStfDetByMinSal(stf);

if(answer == null){

System.out.println("No such staff with years of experience greater than 5 available");

else{

System.out.println(answer.getStaffId());

System.out.println(answer.getStaffName());

public static Staff findStfDetByMinSal(Staff[] stf){

Staff dummy =null;

double min = Double.MAX_VALUE;

for (int i = 0; i < stf.length; i++) {

if((stf[i].getYearsOfExperience()>5) && (stf[i].getCurrentSalary()<min)){

min = stf[i].getCurrentSalary();

dummy = stf[i];

return dummy;

public static double findAvgSalForDept(Staff[] stf,String deptName){

double sum = 0;

int count =0;

for (int i = 0; i < stf.length; i++) {

if(stf[i].getDeptName().equalsIgnoreCase(deptName)){

sum = sum+ stf[i].getCurrentSalary();

count++;

}
if(count>0){

return (double) sum/count;

else

return -1;

class Staff{

private int staffId;

private String staffName;

private String deptName;

private float yearsOfExperience;

private double currentSalary;

public Staff(int staffId,String staffName,String deptName,float yearsOfExperience,double currentSalary){

this.staffId = staffId;

this.staffName = staffName;

this.deptName = deptName;

this.yearsOfExperience = yearsOfExperience;

this.currentSalary = currentSalary;

public int getStaffId() {

return staffId;

public String getStaffName() {

return staffName;

public String getDeptName() {

return deptName;

}
public float getYearsOfExperience() {

return yearsOfExperience;

public double getCurrentSalary() {

return currentSalary;

You might also like