Intern

 avatar
unknown
plain_text
25 days ago
4.2 kB
1
Indexable
import java.util.Calendar;

/**
 * L01-Create a java console program to manage Candidates ò company.
 *
 * @author KhangTNCE180189 - Trần Nhất Khang
 */
public class Intern extends Candidate {
    public static final int MIN_AGE = 21; // Minimum age for intern candidates
    public static final int MAX_AGE = 65; // Maximum age for experience candidates

    private String major; // Candidate's major
    private String semester; // Candidate's current semester
    private String universityName; // Name of the university

    /**
     * Constructor for the Intern 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 (2 for Intern).
     * @param major          The candidate's major.
     * @param semester       The candidate's current semester.
     * @param universityName The name of the university the candidate is
     *                       attending.
     */
    public Intern(String candidateId, String firstName, String lastName, int birthDate, String address,
            String phone, String email, String candidateType, String major, String semester, String universityName) {
        super(candidateId, firstName, lastName, birthDate, address, phone, email, candidateType);
        this.major = major;
        this.semester = semester;
        this.universityName = universityName;

        // Validate birth date during construction
        if (!isValidBirthDate(birthDate)) {
            throw new IllegalArgumentException("Invalid birth date for Intern candidate.");
        }
    }

    /**
     * Validates the birth year for Intern 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;
    }


    /**
     * Get the major of the intern.
     *
     * @return Major.
     */
    public String getMajor() {
        return major; // Return the major of the intern
    }

    /**
     * Set the major of the intern.
     *
     * @param major Major to set.
     */
    public void setMajor(String major) {
        this.major = major; // Set the major of the intern
    }

    /**
     * Get the current semester of the intern.
     *
     * @return Semester.
     */
    public String getSemester() {
        return semester; // Return the current semester of the intern
    }

    /**
     * Set the current semester of the intern.
     *
     * @param semester Semester to set.
     */
    public void setSemester(String semester) {
        this.semester = semester; // Set the current semester of the intern
    }

    /**
     * Get the name of the university.
     *
     * @return University name.
     */
    public String getUniversityName() {
        return universityName; // Return the name of the university
    }

    /**
     * Set the name of the university.
     *
     * @param universityName University name to set.
     */
    public void setUniversityName(String universityName) {
        this.universityName = universityName; // Set the name of the university
    }

    /**
     * Method to display detailed information for an intern candidate. This
     * method overrides the printDetails method from the Candidate class to
     * include specific details for intern candidates.
     */
    @Override
    public String toString() {
        return super.toString() + String.format(" | Major: %s | Semester: %s | University: %s",
                major, semester, universityName);
    }
}
Editor is loading...
Leave a Comment