Intelligent Candidate Matcher for Recruitment Based on Skills and Experience,Java
👤 Sharing: AI
```java
import java.util.*;
public class IntelligentCandidateMatcher {
/**
* Represents a candidate with their skills and experience.
*/
static class Candidate {
String name;
List<String> skills;
int yearsOfExperience;
public Candidate(String name, List<String> skills, int yearsOfExperience) {
this.name = name;
this.skills = skills;
this.yearsOfExperience = yearsOfExperience;
}
public String getName() {
return name;
}
public List<String> getSkills() {
return skills;
}
public int getYearsOfExperience() {
return yearsOfExperience;
}
@Override
public String toString() {
return "Candidate{" +
"name='" + name + '\'' +
", skills=" + skills +
", yearsOfExperience=" + yearsOfExperience +
'}';
}
}
/**
* Represents a job requirement with required skills and experience.
*/
static class JobRequirement {
String jobTitle;
List<String> requiredSkills;
int requiredExperience;
public JobRequirement(String jobTitle, List<String> requiredSkills, int requiredExperience) {
this.jobTitle = jobTitle;
this.requiredSkills = requiredSkills;
this.requiredExperience = requiredExperience;
}
public String getJobTitle() {
return jobTitle;
}
public List<String> getRequiredSkills() {
return requiredSkills;
}
public int getRequiredExperience() {
return requiredExperience;
}
@Override
public String toString() {
return "JobRequirement{" +
"jobTitle='" + jobTitle + '\'' +
", requiredSkills=" + requiredSkills +
", requiredExperience=" + requiredExperience +
'}';
}
}
/**
* Calculates a match score between a candidate and a job requirement.
*
* @param candidate The candidate to evaluate.
* @param jobRequirement The job requirement to match against.
* @return A match score (higher is better). Returns 0 if no skills match.
*/
public static double calculateMatchScore(Candidate candidate, JobRequirement jobRequirement) {
List<String> candidateSkills = candidate.getSkills();
List<String> requiredSkills = jobRequirement.getRequiredSkills();
// Calculate skill match score. Simple intersection for now.
int skillMatches = 0;
for (String skill : candidateSkills) {
if (requiredSkills.contains(skill)) {
skillMatches++;
}
}
if (skillMatches == 0) { // No skills matched, no point in calculating further
return 0;
}
double skillMatchPercentage = (double) skillMatches / requiredSkills.size();
// Calculate experience match score.
double experienceScore;
int experienceDifference = candidate.getYearsOfExperience() - jobRequirement.getRequiredExperience();
if (experienceDifference >= 0) {
// Candidate has enough or more experience. Award full score. Optionally, give a bonus for extra.
experienceScore = 1.0; // Full score if enough or more
// experienceScore = Math.min(1.0 + (experienceDifference * 0.1), 1.5); // Bonus for extra experience, but capped.
} else {
// Candidate has less experience. Scale the score.
experienceScore = (double) candidate.getYearsOfExperience() / jobRequirement.getRequiredExperience();
}
experienceScore = Math.max(0, Math.min(experienceScore, 1.0)); // Ensure score is within 0 and 1
// Combine skill and experience scores (weighted average). Adjust weights as needed.
double skillWeight = 0.7;
double experienceWeight = 0.3;
return (skillMatchPercentage * skillWeight) + (experienceScore * experienceWeight);
}
public static void main(String[] args) {
// Sample data (candidates and job requirements)
List<Candidate> candidates = new ArrayList<>();
candidates.add(new Candidate("Alice Smith", Arrays.asList("Java", "Spring Boot", "REST API", "SQL"), 5));
candidates.add(new Candidate("Bob Johnson", Arrays.asList("Python", "Data Analysis", "Machine Learning"), 3));
candidates.add(new Candidate("Charlie Brown", Arrays.asList("Java", "SQL", "Git", "Docker"), 2));
candidates.add(new Candidate("David Lee", Arrays.asList("C++", "Embedded Systems", "RTOS"), 7));
candidates.add(new Candidate("Eve Williams", Arrays.asList("Java", "Spring", "Hibernate", "JavaScript"), 6));
List<JobRequirement> jobRequirements = new ArrayList<>();
jobRequirements.add(new JobRequirement("Java Developer", Arrays.asList("Java", "Spring Boot", "REST API", "SQL"), 3));
jobRequirements.add(new JobRequirement("Data Scientist", Arrays.asList("Python", "Data Analysis", "Machine Learning", "Statistics"), 5));
jobRequirements.add(new JobRequirement("Software Engineer", Arrays.asList("Java", "SQL", "Git", "Docker", "AWS"), 1));
// Find the best candidate for each job requirement.
for (JobRequirement jobRequirement : jobRequirements) {
Candidate bestCandidate = null;
double bestMatchScore = 0;
for (Candidate candidate : candidates) {
double matchScore = calculateMatchScore(candidate, jobRequirement);
System.out.println("Match score for " + candidate.getName() + " for " + jobRequirement.getJobTitle() + ": " + matchScore); //Debug
if (matchScore > bestMatchScore) {
bestMatchScore = matchScore;
bestCandidate = candidate;
}
}
if (bestCandidate != null) {
System.out.println("\nBest candidate for " + jobRequirement.getJobTitle() + " is " + bestCandidate.getName() +
" with a match score of " + bestMatchScore);
} else {
System.out.println("\nNo suitable candidate found for " + jobRequirement.getJobTitle());
}
}
}
}
```
Key improvements and explanations:
* **Clear Class Structure:** Uses `Candidate` and `JobRequirement` classes to clearly represent the data. This makes the code more organized and readable.
* **`calculateMatchScore` Function:** This is the core logic. It now calculates a score based on the overlap of skills and the experience level.
* **Skill Matching:** The `calculateMatchScore` now finds the intersection of candidate skills and required skills to get the skill match score.
* **Experience Matching:** The experience score is calculated to reward candidates with enough or more experience. If they have less experience, a proportion of the score is awarded based on how close they are to the required years of experience. The score is clamped between 0 and 1.
* **Weighted Average:** The match score combines skill and experience scores using a weighted average. You can easily adjust the `skillWeight` and `experienceWeight` to prioritize skills or experience more. Crucially, I've added weights that add up to 1 to make the resulting score meaningful.
* **No Matches Handling:** The code now returns a score of 0 if *no* skills match. This prevents misleading scores when a candidate completely lacks the necessary skills.
* **`toString()` methods:** Added `toString()` methods to the `Candidate` and `JobRequirement` classes to make debugging and output easier to read.
* **Example Usage:** The `main` method shows how to create `Candidate` and `JobRequirement` objects and use the `calculateMatchScore` function.
* **Readability:** Comments explain each step, making the code easier to understand. Variables are named descriptively.
* **Modularity:** The `calculateMatchScore` function is separate from the `main` method, making it easier to test and reuse.
* **Error Handling:** Includes `Math.max(0, Math.min(experienceScore, 1.0))` to ensure that the experience score stays within a valid range (0 to 1). Handles cases where a candidate has less experience than required.
* **Debug Print Statement:** Includes `System.out.println` statement inside the loop to provide detailed information about match scores for each candidate, which is helpful for debugging and understanding the matching process.
* **Clear Output:** The output is now more user-friendly, showing the best candidate for each job and their match score. It also handles the case where no suitable candidate is found.
* **Realistic Data:** Added more realistic candidate and job requirement examples.
* **Bonus Experience:** Added an optional line to `calculateMatchScore` to give bonus points for extra experience.
How to compile and run:
1. **Save:** Save the code as `IntelligentCandidateMatcher.java`.
2. **Compile:** Open a terminal or command prompt and navigate to the directory where you saved the file. Compile the code using the command:
```bash
javac IntelligentCandidateMatcher.java
```
3. **Run:** Run the compiled code using the command:
```bash
java IntelligentCandidateMatcher
```
The output will show the best candidate for each job and their corresponding match score. You can adjust the data, weights, and scoring logic to customize the matcher for your specific needs.
👁️ Viewed: 4
Comments