0% found this document useful (0 votes)
22 views2 pages

create The Constructor Here: Import Import Class

The document contains Java code for a class that checks if a list of candidates are all natives based on their locality and finds the youngest candidate. It takes in a list of candidates, each with a name, locality and age. It has methods to check if all are natives and return the youngest candidate.

Uploaded by

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

create The Constructor Here: Import Import Class

The document contains Java code for a class that checks if a list of candidates are all natives based on their locality and finds the youngest candidate. It takes in a list of candidates, each with a name, locality and age. It has methods to check if all are natives and return the youngest candidate.

Uploaded by

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

import 

java.io.*;
import java.util.*;

class Candidates
{
    //Create the Constructor here
    String name;
    String locality;
    int age;
    public Candidates(String name,String locality,int age){
        this.name = name;
        this.locality = locality;
        this.age = age;
}

class Interview_Candidates
{
    boolean areNatives(ArrayList<Candidates> candidatesList)
    {
        //Enter your Code here
        int res = (int)candidatesList.stream().filter((c) -> 
        c.locality.equals("Native")).count();
        return res == candidatesList.size();
    }
    
    Candidates youngestCandidate(ArrayList<Candidates> candidates
List)
    {
        //Enter your Code here
        Collections.sort(candidatesList,(o1,o2) -> o1.age - o
2.age);
        return candidatesList.get(0);
    }
}

public class Interview_CandidatesMain
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReade
r(System.in));
        ArrayList<Candidates> candidatesList=new ArrayList<>();
                
         int n=Integer.parseInt(br.readLine().trim());
         
         for(int i=0;i<n;i++)
         {
             String inp=br.readLine();
             String inparr[]=inp.split("-");
             
             Candidates cnd=new Candidates( inparr[0], inparr[1], 
Integer.parseInt(inparr[2]) );
             candidatesList.add(cnd);         
         }
         
         
         Interview_Candidates ic=new Interview_Candidates();
         
         boolean ans= ic.areNatives(candidatesList);
         if(ans)
                System.out.println("All candidates are Natives");
         else
                System.out.println("All candidates are not Native
s");
         
         
          Candidates youngest=ic.youngestCandidate(candidatesList
);
        
          System.out.println("Details of the Candidate with young
est age : Name = "+youngest.name+", Locality = "+youngest.localit
y+", Age = "+youngest.age);
    }
}

You might also like