1.
Return Employee of second Highest Salary
import java.util.*;
class Employee
{
    private int EmployeeId;
    private String EmployeeName;
    private int age;
    private char gender;
    private double salary;
    public Employee(int EmployeeId,String EmployeeName,int age,char gender,double
salary)
    {
        this.EmployeeId=EmployeeId;
        this.EmployeeName=EmployeeName;
        this.age=age;
        this.gender=gender;
        this.salary=salary;
    }
    public int getEmpId()
    {
        return EmployeeId;
    }
    public String getEmployeName()
    {
        return EmployeeName;
    }
    public int getAge()
    {
        return age;
    }
    public char getGender()
    {
        return gender;
    }
    public double getSalary()
    {
        return salary;
    }
}
 public class Main
{
    public static Employee getEmpWithSecLowestSalry(Employee[] obj)
    {
        Employee minn=null;
        Employee sec_min=null;
        for(Employee emp: obj)
        {
            if(minn==null || minn.getSalary()>emp.getSalary())
            {
                sec_min=minn;
                minn=emp;
            }
            else if ((sec_min == null || emp.getSalary() < sec_min.getSalary())
                    && emp.getSalary() > minn.getSalary()) {
                sec_min = emp;
            }
    }
        return sec_min;
    }
    public static int countBasedOnAge(Employee[] obj,int age)
    {
        int count=0;
        for(Employee emp: obj)
        {
            if(age==emp.getAge())
            {
                count++;
            }
        }
        return count;
    }
      public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            Employee[] emp=new Employee[n];
            for(int i=0;i<n;i++)
            {
                int a=sc.nextInt();
                sc.nextLine();
                String b=sc.nextLine();
                int c=sc.nextInt();
                sc.nextLine();
                char d=sc.next().charAt(0);
                sc.nextLine();
                double e=sc.nextDouble();
                sc.nextLine();
                emp[i]=new Employee(a,b,c,d,e);
            }
            int age=sc.nextInt();
                Employee res=getEmpWithSecLowestSalry(emp);
                if(res!=null)
                {
                     System.out.println(res.getEmpId());
                     System.out.println(res.getEmployeName());
                }
                       else
                {
                     System.out.println("Null");
                }
                int res2=countBasedOnAge(emp,age);
                if(res2!=0)
                {
                     System.out.println(res2);
                }
                else
                {
                     System.out.println("No employee found for the given age");
                }
        }
}
2. sort array object
import java.util.*;
class Course
{
    private int courseId;
    private String courseName;
    private String courseAdmin;
    private int quiz;
    private int handson;
    public Course(int courseId,String courseName,String courseAdmin,int quiz,int
handson)
    {
         this.courseId=courseId;
         this.courseName=courseName;
         this.courseAdmin=courseAdmin;
         this.quiz=quiz;
         this.handson=handson;
    }
    public void setCourseId(int courseId)
    {
         this.courseId=courseId;
    }
    public int getCourseId()
    {
         return courseId;
    }
    public String getCourseName()
    {
         return courseName;
    }
    public void setCourseName(String courseName)
    {
         this.courseName= courseName;
    }
    public String getCourseAdmin()
    {
         return courseAdmin;
    }
    public void setCourseAdmin(String courseAdmin)
    {
         this.courseAdmin=courseAdmin;
    }
    public int getQuiz()
    {
         return quiz;
    }
    public void setQuiz(int quiz)
    {
         this.quiz=quiz;
    }
    public int getHandson()
    {
         return handson;
    }
    public void setHandson(int handson)
    {
        this.handson=handson;
    }
}
public class Main
{
    public static double findAvgByAdmin(Course[] arr, String Admin)
    {
        int count=0;
        double avg=0;
        for(Course course: arr)
        {
            if(Admin.equalsIgnoreCase(course.getCourseAdmin()))
            {
                count++;
                avg+=course.getQuiz();
            }
        }
        if(count==0)
        {
            return 0;
        }
        return avg/count;
    }
    public static Course[] setCourseByHandsOn(Course[] arr,int handson)
    {
            List<Course> obj=new ArrayList<>();
            int count=0;
            for(Course cs: arr)
            {
                if(cs.getHandson()<handson)
                {
                    count++;
                }
            }
            Course[] obj2=new Course[count];
            int index=0;
            for(Course cs: arr)
            {
                  if(cs.getHandson()<handson)
                {
                     obj2[index++]=cs;
                }
            }
            Arrays.sort(obj2,Comparator.comparingInt(Course:: getQuiz));
            return obj2;
    public static void main(String[] args)
    {
               Scanner sc=new Scanner(System.in);
        int n;
        n=sc.nextInt();
        sc.nextLine();
        Course[] course=new Course[n];
        int i;
         for(i=0;i<n;i++)
         {
             int a=sc.nextInt();
             sc.nextLine();
             String b=sc.nextLine();
             String c=sc.nextLine();
             int d=sc.nextInt();
             sc.nextLine();
             int e=sc.nextInt();
             sc.nextLine();
             course[i]=new Course(a,b,c,d,e);
         }
         String admin=sc.nextLine();
         int quiz=sc.nextInt();
         sc.nextLine();
         double res=findAvgByAdmin(course,admin);
         if(res!=0)
         {
              System.out.println(res);
         }
         else
         {
               System.out.println("No course found");
         }
         Course[] res2=setCourseByHandsOn(course,quiz);
         if(res2!=null)
         {
               for(Course arr: res2)
               {
                     System.out.println(arr.getCourseName());
                      System.out.println(arr.getQuiz());
                }
         }
             else
         {
                System.out.println("No course found with mentiioned attribute");
         }
3.   Return second max employee based on ..........
import java.util.*;
class Employee
{
    private int employeeld;
    private String name;
    private String branch;
    private double rating;
    private boolean transport;
    public Employee(int employeeld,String name,String branch,double rating,boolean
transport)
    {
        this.employeeld=employeeld;
        this.name=name;
        this.branch=branch;
        this.rating=rating;
        this.transport=transport;
    }
    public void setEmployeeld(int employeeld)
    {
        this.employeeld=employeeld;
    }
    public int getEmployeeld()
    {
        return employeeld;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name= name;
    }
    public String getBranch()
    {
        return branch;
    }
    public void setBranch(String branch)
    {
        this.branch=branch;
    }
    public double geRating()
    {
        return rating;
    }
    public void seRating(double rating)
    {
        this.rating=rating;
    }
    public boolean getTransport()
    {
        return transport;
    }
    public void setTransport(boolean transport)
    {
        this.transport=transport;
    }
}
public class Main
{
     public static int findCountOfEmployeesUsingCompTransport(Employee[] arr, String
str)
     {
         int count=0;
         for(Employee emp: arr)
         {
             if(str.equalsIgnoreCase(emp.getBranch()) && emp.getTransport()==true)
             {
                 count++;
            }
        }
        return count;
    }
    public static Employee findEmployeeWithSecondHighestRating(Employee[] arr)
    {
        Employee maxx=null;
        Employee sec_max=null;
        for(Employee obj: arr )
        {
            if(obj.getTransport()==false)
            {
                if(maxx==null || maxx.geRating()<obj.geRating())
                {
                    sec_max=maxx;
                    maxx=obj;
                }
                else if((sec_max==null || sec_max.geRating()<obj.geRating()) &&
obj.geRating()<maxx.geRating())
                {
                    sec_max=obj;
                }
            }
        }
        return sec_max;
    }
    public static void main(String[] args)
    {
               Scanner sc=new Scanner(System.in);
        int n;
        n=sc.nextInt();
        sc.nextLine();
        Employee[] emp=new Employee[n];
        int i;
        for(i=0;i<n;i++)
        {
            int a=sc.nextInt();
            sc.nextLine();
            String b=sc.nextLine();
            String c=sc.nextLine();
            double d=sc.nextDouble();
            sc.nextLine();
            boolean e=sc.nextBoolean();
            sc.nextLine();
            emp[i]=new Employee(a,b,c,d,e);
        }
        String branch=sc.nextLine();
        int res=findCountOfEmployeesUsingCompTransport(emp,branch);
        if(res!=0)
        {
             System.out.println(res);
        }
        else
        {
             System.out.println("Not found with given attribute");
        }
        Employee obj=findEmployeeWithSecondHighestRating(emp);
        if(obj!=null)
        {
               System.out.println(obj.getEmployeeld());
                System.out.println(obj.getName());
        }
          else
        {
             System.out.println("All using company transposrt");
        }
3. Sort array of obj
import java.util.*;
class Medicine
{
    private String medicineName;
    private String batch;
    private String disease;
    private int price;
    public Medicine(String medicineName,String batch,String disease,int price)
    {
         this.medicineName=medicineName;
         this.batch=batch;
         this.disease=disease;
         this.price=price;
    }
    public String getMedicineName()
    {
         return medicineName;
    }
    public void setMedicineName(String medicineName)
    {
         this.medicineName=medicineName;
    }
      public String getBatch()
    {
         return batch;
    }
    public void setBatch(String batch)
    {
         this.batch=batch;
    }
      public String getDisease()
    {
         return disease;
    }
    public void setDisease(String disease)
    {
         this.disease=disease;
    }
      public int getPrice()
    {
        return price;
    }
    public void setPrice(int price)
    {
        this.price=price;
    }
}
public class Main
{
     public static Medicine[] getPriceByDisease(Medicine[] arr, String disease)
         {
             int count=0;
             List<Medicine> med=new ArrayList<>();
             for(Medicine obj: arr)
             {
                  if(disease.equalsIgnoreCase(obj.getDisease()))
                  {
                      med.add(obj);
                      count++;
                  }
             }
            // Collections.sort(med,Comparator.comparingInt(Medicine::getPrice));
             // Medicine[] me=med.toArray(new Medicine[0]);
             Medicine[] me=new Medicine[count];
             int indx=0;
              for(Medicine obj: arr)
              {
                  if(disease.equalsIgnoreCase(obj.getDisease()))
                  {
                      me[indx++]=obj;
                  }
              }
              Arrays.sort(me,Comparator.comparingInt(Medicine::getPrice));
              if(me.length>0)
              {
              return me;
              }
              return null;
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        int i;
        Medicine[] medc=new Medicine[n];
        for(i=0;i<n;i++)
          {
              String a=sc.nextLine();
               String b=sc.nextLine();
                String c=sc.nextLine();
               int d=sc.nextInt();
               sc.nextLine();
               medc[i]=new Medicine(a,b,c,d);
          }
          String dis=sc.nextLine();
          Medicine[] res=getPriceByDisease(medc,dis);
          if(res!=null)
          {
               for(Medicine arr: res)
               {
                   System.out.println(arr.getPrice());
               }
          }
          else
          {
                   System.out.println("No medicine found with given disease");
    }
}
4. Institution based on set and get Rating
import java.util.*;
class Institution
{
      private int instituteId;
      private String instituteName;
      private int noOfStdPlaced;
      private int noOfStdCleared;
      private String location;
      private String grade;
      public Institution(int instituteId,String instituteName,int noOfStdPlaced,int
noOfStdCleared,String location)
      {
            this.instituteId=instituteId;
            this.instituteName=instituteName;
            this.noOfStdPlaced=noOfStdPlaced;
            this.noOfStdCleared=noOfStdCleared;
            this.location=location;
        }
        public int getId()
        {
              return instituteId;
        }
        public void setId(int instituteId)
        {
              this.instituteId=instituteId;
        }
     public String getName()
     {
           return instituteName;
     }
     public void setName()
     {
           this.instituteName=instituteName;
     }
     public int getPlacedStd()
     {
           return noOfStdPlaced;
     }
     public void setPlacedStd(int noOfStdPlaced)
     {
           this.noOfStdPlaced=noOfStdPlaced;
     }
     public int getClearedStd()
     {
           return noOfStdCleared;
     }
     public void setClearedStd(int noOfStdCleared)
     {
           this.noOfStdCleared=noOfStdCleared;
     }
     public String getLocation()
     {
           return location;
     }
     public void setLocation(String location)
     {
           this.location=location;
     }
     public String getGrade()
     {
           return grade;
     }
     public void setGrade(String grade)
     {
           this.grade=grade;
     }
public class Main
{
      public static int   FindNumClearanceByLocation(Institution[] arr, String
location)
      {
           int sum=0;
           for(Institution ins: arr)
           {
                 if(location.equalsIgnoreCase(ins.getLocation()))
                 {
                       sum=sum+ins.getClearedStd();
                 }
           }
           if(sum>0)
           {
                 return sum;
           }
           return 0;
     }
      public static   Institution UpdateInstitutionGrade(Institution[] arr,String
nameIns)
      {
            Institution obj=null;
            int rating=0;
            for(Institution ins: arr)
            {
                  if(nameIns.equalsIgnoreCase(ins.getName()))
                  {
                        rating=(ins.getPlacedStd()*100)/ins.getClearedStd();
                        obj=ins;
                  }
           }
   if(rating>=80)
                 {
                         obj.setGrade("A");
                 }
                 else
                 {
                         obj.setGrade("B");
                 }
           return obj;
     public static void main(String[] args)
     {
           Scanner sc=new Scanner(System.in);
           int n=sc.nextInt();
           sc.nextLine();
           Institution[] ins=new Institution[n];
           int i;
           for(i=0; i<n; i++)
           {
                 int a=sc.nextInt();
                 sc.nextLine();
                 String b=sc.nextLine();
                 int c=sc.nextInt();
                 sc.nextLine();
                 int d=sc.nextInt();
                 sc.nextLine();
                 String e=sc.nextLine();
            //    String f=sc.nextLine();
                  ins[i]=new Institution(a,b,c,d,e);
            }
            String location=sc.nextLine();
            String NameIns=sc.nextLine();
            int res1=FindNumClearanceByLocation(ins,location);
            if(res1>0)
            {
                   System.out.println(res1);
            }
            else
            {
             System.out.println("There are no cleared students in this particular
location.");
            }
            Institution obj=UpdateInstitutionGrade(ins,NameIns);
            if(obj!=null)
            {
                 System.out.println(obj.getName()+"::"+obj.getGrade());
            }
            else
            {
                 System.out.println("No Institute is avialable with the specified
name");
            }
      }
}
5.   max and return obj
import java.util.*;
class TravelAgency
{
    private int regNo;
    private String agencyName;
    private String packageType;
    private int price;
    private boolean flightFacility;
    public TravelAgency(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;
    }
     public int getRegNo()
     {
         return regNo;
     }
        public void getRegNo(int regNo)
     {
         this.regNo=regNo;
     }
     public String getAgencyName()
     {
        return agencyName;
   }
       public void setAgencyName(String agencyName)
   {
       this.agencyName=agencyName;
   }
   public String getPackageType()
   {
       return packageType;
   }
     public void getPackageType(String packageType)
   {
       this.packageType=packageType;
   }
   public int getPrice()
   {
       return price;
   }
     public void setPrice(int price)
   {
       this.price=price;
   }
   public boolean getFlightFacility()
   {
       return flightFacility;
   }
   public void getFlightFacility(boolean flightFacility)
   {
       this.flightFacility=flightFacility;
   }
}
public class Main
{
   public static int findAgencyWithHighestPackagePrice(TravelAgency[] arr)
   {
       int maxx=Integer.MIN_VALUE;
        for(TravelAgency trv: arr)
        {
            if(maxx<trv.getPrice())
            {
                maxx=trv.getPrice();
             }
         }
       return maxx;
   }
    public static TravelAgency AgencyDetailForGivenIdAndType(TravelAgency[]
arr,int reg,String packageType)
    {
        TravelAgency obj=null;
        for(TravelAgency trv: arr)
        {
            if(trv.getFlightFacility() && reg==trv.getRegNo() &&
packageType.equalsIgnoreCase(trv.getPackageType()))
            {
                obj=trv;
              }
          }
          return obj;
    }
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        TravelAgency[] travel=new TravelAgency[n];
        int i;
          for(i=0;i<n;i++)
          {
              int a=sc.nextInt();
              sc.nextLine();
              String b=sc.nextLine();
              String c=sc.nextLine();
              int d=sc.nextInt();
              sc.nextLine();
              boolean e=sc.nextBoolean();
              sc.nextLine();
              travel[i]=new TravelAgency(a,b,c,d,e);
          }
          int reg=sc.nextInt();
          sc.nextLine();
          String typ=sc.nextLine();
        int res1=findAgencyWithHighestPackagePrice(travel);
          System.out.println(res1);
          TravelAgency res2=AgencyDetailForGivenIdAndType(travel,reg,typ);
          System.out.println(res2.getAgencyName()+"::"+res2.getPrice());
    }
}