随笔 - 434,  文章 - 0,  评论 - 463,  阅读 - 46万

哈喽,我是兔哥呀,今天就让我们继续这个JavaSE成神之路!

这一节啊,咱们要学习的内容是...啊不对,这一节咱们来考试,算是期中考试吧。

目前我们已经学习了Java的很多基础知识了,那么怎么检查自己到底学的怎么样呢?

最好的办法,就是通过一场考试,来检验一下学习效果啦。

首先来看下业务场景,我们是一家软件公司,现在新发布一个【java高级软件开发】的招聘,预计招收2个人,月薪25k,要求年龄25周岁以下,并且需要有30年工作经验,不符合要求的简历将被系统自动过滤。

请编写Java程序来实现这个简历筛查工作。(忽略面试环节,符合招聘要求的自动视为录取)

需求分析:

1、简历类

属性:姓名(String)、年龄(int)、工作年限(int)、投递岗位(用岗位类的引用) 方法:介绍(打印个人信息)

2、岗位类 属性:岗位名称(String)、月薪(float)、简历(用简历类的数组)、已接收简历(int) 方法:介绍(打印岗位信息)、添加简历(需要对年龄和工作年限进行校验)

自行编写测试类,要求注释清晰,类结构合理。

参考答案:

简历类

package com.company.bean;

/**
 *
 * Resume类用于定义简历信息
 *
 * @author 作者名
 * @version 1.0
 *
 */
public class Resume {
    // 姓名
    private String name;
    // 年龄
    private int age;
    // 工作年限
    private int workYear;
    // 职位
    private Position position;

    /**
     * 构造函数
     * @param name 姓名
     * @param age 年龄
     * @param workYear 工作年限
     * @param position 职位
     */
    public Resume(String name, int age, int workYear, Position position) {
        this.name = name;
        this.age = age;
        this.workYear = workYear;
        this.position = position;
    }

    /**
     * 获取姓名
     * @return 姓名
     */
    public String getName() {
        return name;
    }

    /**
     * 设置姓名
     * @param name 姓名
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取年龄
     * @return 年龄
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置年龄
     * @param age 年龄
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取工作年限
     * @return 工作年限
     */
    public int getWorkYear() {
        return workYear;
    }

    /**
     * 设置工作年限
     * @param workYear 工作年限
     */
    public void setWorkYear(int workYear) {
        this.workYear = workYear;
    }

    /**
     * 获取职位
     * @return 职位
     */
    public Position getPosition() {
        return position;
    }

    /**
     * 设置职位
     * @param position 职位
     */
    public void setPosition(Position position) {
        this.position = position;
    }

    /**
     * 介绍简历信息
     */
    public void introduce() {
        System.out.println("姓名: " + name + " ,年龄: " + age + " ,工作年限: " + workYear + " ,职位: " + position.getName());
    }
}

岗位类

package com.company.bean;

/**
 *
 * Position类用于定义职位信息
 *
 * @author 作者名
 * @version 1.0
 *
 */
public class Position {
    // 职位名称
    private String name;
    // 职位薪资
    private double salary;
    // 简历信息
    private Resume[] resumes = new Resume[2];
    // 已接受的简历数量
    private int acceptedResumes = 0;

    /**
     * 构造函数
     * @param name 职位名称
     * @param salary 职位薪资
     */
    public Position(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }

    /**
     * 获取职位名称
     * @return 职位名称
     */
    public String getName() {
        return name;
    }

    /**
     * 获取职位薪资
     * @return 职位薪资
     */
    public double getSalary() {
        return salary;
    }

    /**
     *  介绍职位信息
     */
    public void introduce() {
        System.out.println("职位:" + name + ",薪资:" + salary);
    }

    /**
     * 添加简历
     * @param resume 简历信息
     */
    public void addResume(Resume resume) {

        //判断招聘是否结束?
        if(acceptedResumes == resumes.length ){
            System.out.println("已经招满了,不招了!");
            System.exit(0);
            return;
        }
        // 年龄小于25岁并且工作年限大于30年的简历接受
        if (resume.getAge() < 25 && resume.getWorkYear() > 30) {
            resumes[acceptedResumes] = resume;
            acceptedResumes++;

        } else {
            System.out.println(resume.getName() + "的简历被刷掉了!");
        }

    }
}

测试类

package com.company.test;

import com.company.bean.Position;
import com.company.bean.Resume;

// 测试类
public class TestPosition {
    public static void main(String[] args) {
        Position position = new Position("Java高级软件开发"25000);
        position.introduce();

        Resume resume1 = new Resume("张三"2432, position);
        position.addResume(resume1);
        resume1.introduce();

        Resume resume2 = new Resume("李四"3030, position);
        resume2.introduce();
        position.addResume(resume2);

        Resume resume3 = new Resume("王五"2238, position);
        position.addResume(resume3);
        resume3.introduce();

        Resume resume4 = new Resume("赵六"2238, position);
        position.addResume(resume4);
        resume4.introduce();
    }
}

测试结果

职位:Java高级软件开发,薪资:25000.0

姓名: 张三 ,年龄: 24 ,工作年限: 32 ,职位: Java高级软件开发

姓名: 李四 ,年龄: 30 ,工作年限: 30 ,职位: Java高级软件开发

李四的简历被刷掉了!

姓名: 王五 ,年龄: 22 ,工作年限: 38 ,职位: Java高级软件开发

已经招满了,不招了!

 

posted on   剽悍一小兔  阅读(17)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-03-08 前端面试:浅拷贝和深拷贝的区别?

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示