Fresher
unknown
plain_text
7 months ago
4.9 kB
4
Indexable
import java.util.Calendar;
/**
* L01-Create a java console program to manage Candidates ò company.
*
* @author KhangTNCE180189 - Trần Nhất Khang
*/
public class Fresher extends Candidate {
public static final int MIN_AGE = 22; // Minimum age for fresher candidates
public static final int MAX_AGE = 65; // Maximum age for experience candidates
private int graduationYear; // Graduation year
private String graduationRank; // Graduation rank
private String education; // Education institution name
/**
* Constructor for the Fresher class.
*
* @param candidateId The candidate's ID.
* @param firstName The candidate's first name.
* @param lastName The candidate's last name.
* @param birthDate The candidate's birth year.
* @param address The candidate's address.
* @param phone The candidate's phone number.
* @param email The candidate's email.
* @param candidateType The type of the candidate (1 for Fresher).
* @param graduationYear The year of graduation.
* @param graduationRank The graduation rank (e.g., Excellent, Good).
* @param education The name of the university or educational institution.
*/
public Fresher(String candidateId, String firstName, String lastName, int birthDate, String address,
String phone, String email, String candidateType, int graduationYear, String graduationRank,
String education) {
super(candidateId, firstName, lastName, birthDate, address, phone, email, candidateType);
this.graduationYear = graduationYear;
this.graduationRank = graduationRank;
this.education = education;
// Validate birth date during construction
if (!isValidBirthDate(birthDate)) {
throw new IllegalArgumentException("Invalid birth date for Fresher candidate.");
}
}
/**
* Validates the birth year for Fresher candidates.
*
* @param birthDate The candidate's birth year.
* @return true if valid, otherwise false.
*/
public static boolean isValidBirthDate(int birthDate) {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
return (currentYear - birthDate) >= MIN_AGE &&
(currentYear - birthDate) <= MAX_AGE;
}
/**
* Validates if the input string is a valid integer.
*
* @param input the input string
* @return true if the input is a valid integer, otherwise false
*/
public boolean isValidInteger(String input) {
if (input == null) {
return false; // Null input is not valid
}
try {
Integer.parseInt(input); // Attempt to parse the input as an integer
return true; // Parsing succeeded, input is valid
} catch (NumberFormatException e) {
return false; // Parsing failed, input is not a valid integer
}
}
/**
* Get the graduation year.
*
* @return Graduation year.
*/
public int getGraduationYear() {
return graduationYear; // Return the graduation year
}
/**
* Set the graduation year.
*
* @param graduationYear Graduation year to set.
*/
public void setGraduationYear(int graduationYear) {
this.graduationYear = graduationYear; // Set the graduation year
}
/**
* Get the graduation rank.
*
* @return Graduation rank.
*/
public String getGraduationRank() {
return graduationRank; // Return the graduation rank
}
/**
* Set the graduation rank.
*
* @param graduationRank Graduation rank to set.
*/
public void setGraduationRank(String graduationRank) {
this.graduationRank = graduationRank; // Set the graduation rank
}
/**
* Get the name of the university.
*
* @return University name.
*/
public String getEducation() {
return education; // Return the name of the university
}
/**
* Set the name of the university.
*
* @param education University name to set.
*/
public void setEducation(String education) {
this.education = education; // Set the name of the university
}
/**
* Method to display detailed information for a fresher candidate. This
* method overrides the printDetails method from the Candidate class to
* include specific details for fresher candidates.
*/
@Override
public String toString() {
return super.toString() + String.format(" | Graduation Year: %d | Rank: %s | Education: %s",
graduationYear, graduationRank, education);
}
}
Editor is loading...
Leave a Comment