Mock PRA SBQ 1
------------------------------------Unix------------------------------------------
awk 'BEGIN{FS="|"; eco=0; gco=0; IGNORECASE=1}
{
if($3 == "English")
{eco++};
if( $3 == "Geography")
{gco++};
}
END{
if(gco==0 && eco==0){
print "No records found.";}
else{
print "Count of students for English Major = "eco;
print "Count of students for Geography Major = "gco;
}
}'
------------------------------------Java
Solution------------------------------------------
import java.util.*;
class College
{
private int id,cNo,pcode;
private String name,addr;
public College(int id, int cNo, int pcode, String name, String addr)
{
super();
this.id = id;
this.cNo = cNo;
this.pcode = pcode;
this.name = name;
this.addr = addr;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public int getContactNo()
{
return cNo;
}
public void setContactNo(int cNo)
{
this.cNo = cNo;
}
public int getPincode()
{
return pcode;
}
public void setPincode(int pcode)
{
this.pcode = pcode;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAddress()
{
return addr;
}
public void setAddress(String addr)
{
this.addr = addr;
}
}
public class Solution
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
College college[] = new College[n];
for(int i=0; i<college.length; i++)
{
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
int contactNo= sc.nextInt();
sc.nextLine();
String address = sc.nextLine();
int pincode = sc.nextInt();
college[i] = new College(id, contactNo, pincode, name, address);
}
sc.nextLine();
String searchaddress = sc.nextLine();
College res1 = findCollegeWithMaximumPincode(college);
if(res1!=null)
{
System.out.println("id-"+res1.getId());
System.out.println("name-"+res1.getName());
System.out.println("contactNo-"+res1.getContactNo());
System.out.println("address-"+res1.getAddress());
System.out.println("pincode-"+res1.getPincode());
}
else
{
System.out.println("No College found with mentioned attribute");
}
College res2 =searchCollegeByAddress(college,searchaddress);
if(res2!=null)
{
System.out.println("id-"+res2.getId());
System.out.println("name-"+res2.getName());
System.out.println("contactNo-"+res2.getContactNo());
System.out.println("address-"+res2.getAddress());
System.out.println("pincode-"+res2.getPincode());
}
else
{
System.out.println("No College found with mentioned attribute.");
}
}
public static College findCollegeWithMaximumPincode(College col[])
{
int max=0;
College result =null;
for(int i=0; i<col.length; i++){
if(col[i].getPincode() > max){
result = col[i];
max= col[i].getPincode();
}
}
if(result!=null)
return result;
else
return null;
}
public static College searchCollegeByAddress(College c[],String address)
{
College ans=null;
for(int i=0;i<c.length;i++)
{
if(c[i].getAddress().equalsIgnoreCase(address))
{
ans=c[i];
}
}
if(ans!=null)
return ans;
else
return null;
}
}
Mock PRA SBQ 2
------------------------------------Unix------------------------------------------
awk 'BEGIN{FS=" ";total=0;IGNORECASE=1;}
NR>1{
if($3 == "sales"){
total+=$4;
}
}END{
if(total > 0){
print("Total Salary = "total);
}
else{
print("No employee found.");
}
}'
-----------------------------Java Solution-----------------------------------------
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[] ){
int number;
String name;
double price;
Scanner sc = new Scanner(System.in);
Vehicle[] vehicles = new Vehicle[4];
int n = sc.nextInt();
for(int i=0;i<n;i++){
number = sc.nextInt();sc.nextLine();
name = sc.nextLine();
price = sc.nextDouble();
vehicles[i] = new Vehicle(number,name,price);
}
sc.nextLine();
String vehicle1 = sc.nextLine();
Vehicle vehicle = findVehicleWithMinimumPrice(vehicles);
Vehicle vehicle2 = searchVehicleByName(vehicles,vehicle1);
if (vehicle == null){
System.out.println("No Vehicle found with mentioned attribute");
}
else{
System.out.println("number-"+vehicle.getNumber());
System.out.println("name-"+vehicle.getName());
System.out.println("price-"+vehicle.getPrice());
}
if (vehicle2 == null){
System.out.println("No Vehicle found with mentioned attribute");
}
else{
System.out.println("number-"+vehicle2.getNumber());
System.out.println("name-"+vehicle2.getName());
System.out.println("price-"+vehicle2.getPrice());
}
public static Vehicle findVehicleWithMinimumPrice(Vehicle [] vehicles){
double min=vehicles[0].getPrice();
int f = -1;
for(int i=0;i<vehicles.length;i++){
if(vehicles[i].getPrice() <= min){
min = vehicles[i].getPrice();
}
}
for(int i=0;i<vehicles.length;i++){
if(vehicles[i].getPrice() == min){
f=i;
}
}
if(f==-1){
return null;
}
else{
return vehicles[f];
}
public static Vehicle searchVehicleByName(Vehicle [] vehicles,String
vehicle1){
int m=0;
for(int i=0;i<vehicles.length;i++){
if(vehicles[i].getName().equalsIgnoreCase(vehicle1)){
m=i;
}
}
if(m==0){
return null;
}
else{
return vehicles[m];
}
}
}
class Vehicle {
private int number;
private String name;
private double price;
public Vehicle(int number,String name, double price){
this.number = number;
this.name = name;
this.price = price;
}
public int getNumber(){
return number;
}
public String getName(){
return name;
}
public double getPrice(){
return price;
}
}
Mock PRA SBQ 3
-----------------------------Unix-----------------------------------------
awk -v a="$4" 'BEGIN {c=0}{FS="-"}{if($4>40000) c++}
END{print "Total count: " c}'
-----------------------------Java Solution-----------------------------------------
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)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Lawyer[] l=new Lawyer[n];
for(int i=0;i<n;i++){
int id=sc.nextInt();sc.nextLine();
String name=sc.nextLine();
double salary=sc.nextDouble();sc.nextLine();
int age=sc.nextInt();sc.nextLine();
l[i]=new Lawyer(id,name,salary,age);
}
String sname=sc.nextLine();
double avg=findAverageAgeOfLawyer(l);
if(avg==0){
System.out.println("No Lawyer found with mentioned attribute.");
}
else{
System.out.println("Average of age "+avg);
}
Lawyer law=searchLawyerByName(l, sname);
if(law==null){
System.out.println("No Lawyer found with mentioned attribute.");
}
else{
System.out.println("id-"+law.getId());
System.out.println("name-"+law.getName());
System.out.println("salary-"+law.getSalary());
System.out.println("age-"+law.getAge());
}
sc.close();
}
public static double findAverageAgeOfLawyer(Lawyer[] l)
{
double sum=0,avg=0;
for(int i=0;i<l.length;i++){
sum+=l[i].getAge();
}
avg=sum/l.length;
if(avg==0)
return 0;
else
return avg;
}
public static Lawyer searchLawyerByName(Lawyer[] l, String sname)
{
Lawyer nameLawyer=l[0];
for(int i=0;i<l.length;i++){
if(l[i].getName().equalsIgnoreCase(sname))
return l[i];
}
return null;
}
class Lawyer
{
int id;
String name;
double salary;
int age;
public Lawyer(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 void setId(int id){
this.id=id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public double getSalary()
{
return salary;
}
public void setSalary(double salary)
{
this.salary=salary;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
}