• JavaIO文件处理习题


    题目:

    “人才管理系统”

    类描述

    人才信息属性姓名性别年龄专业毕业学校掌握技能list集合

    个人简历继承人才信息属性个人简介

    猎头公司属性公司名称地址

    接口描述

    1、增加人才信息

    2、查询人才信息

    3、根据年龄向控制台查询人才信息

    4、根据专业向控制台查询人才信息

    5、查询出技能中掌握java的人才信息

    6、猎头公司可以查看人才系统所有人才

    7、猎头公司根据选择的人才查看个人的简介

    要求

    1、创建三个包一个包为entity存放类一个包为service存放所有属性接口一个包为controller存放测试类

    2、增加人才信息时每个人才信息创建一个文件夹单独存放文件夹名称为姓名文件夹内容为个人信息txt和个人介绍txt

    3、循环展示人才管理系统的文件夹通过判断控制台输入内容查询到相应的人才文件夹读取文件夹中txt内容在控制台展示

    4、所有输出语句均写在测试类中方法只做业务操作

    5、类名要求按照帕斯卡命名法首字母大写其余单词字母均大写例如Student学生类);属性要求按照匈牙利命名法命名属性名=数据类型+描述例如strName姓名),intAge年龄);方法名要求按照驼峰命名法命名首字母小写其余单词首字母大写例如addStudent新增学生

    解答:

    package entity;
    
    import java.util.List;
    
    public class Consume extends Information{
        private String consume;
    
        public Consume(String name, String sex, String age, String aim, String school, String list, String consume) {
            super(name, sex, age, aim, school, list);
            this.consume = consume;
        }
    
        /**
         * @return the consume
         */
        public final String getConsume() {
            return consume;
        }
    
        /**
         * @param consume the consume to set
         */
        public final void setConsume(String consume) {
            this.consume = consume;
        }
    
        
    
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "Consume [name=" + super.getName() + ", sex=" + super.getSex() + ", age=" + super.getAge() + ", aim=" + super.getAim() + ", school=" + super.getSchool()
                    + ", list=" + super.getList() + ", consume=" + consume + "]";
        }
        
    }
    package entity;
    
    import java.awt.Frame;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Scanner;
    
    import javax.annotation.processing.Filer;
    
    import service.JieKou;
    
    public class Hunter implements JieKou {
        ArrayList<Consume> hunterlist = new ArrayList<Consume>();
        private String name;
        private String address;
    
        public Hunter(String name, String address) {
            this.name = name;
            this.address = address;
        }
    
        /**
         * @return the name
         */
        public final String getName() {
            return name;
        }
    
        /**
         * @param name
         *            the name to set
         */
        public final void setName(String name) {
            this.name = name;
        }
    
        /**
         * @return the address
         */
        public final String getAddress() {
            return address;
        }
    
        /**
         * @param address
         *            the address to set
         */
        public final void setAddress(String address) {
            this.address = address;
        }
    
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "Hunter  [name=" + name + ", address=" + address + "]";
        }
    
        @Override
        public void addInformation(String name, String sex, String age, String aim, String school, String list,
                String consume) {
            Consume c = new Consume(name, sex, age, aim, school, list, consume);
            hunterlist.add(c);
    
            File f = new File("D:\RCGLXT\" + name);
            f.mkdir();
            f = new File("D:\RCGLXT\" + name + "\个人信息.txt");
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                FileWriter fw = new FileWriter("D:\RCGLXT\" + name + "\个人信息.txt");
                fw.write(c.toString());
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            f = new File("D:\RCGLXT\" + name + "\个人介绍.txt");
            try {
                FileWriter fw2 = new FileWriter(f);
                fw2.write(c.getConsume());
                fw2.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
    
        }
    
        @Override
        public String findInformation() {
            String str = "";
            File f = new File("D:\RCGLXT");
            File[] filelist = f.listFiles();
            for (File file : filelist) {
                try {
                    FileReader fr = new FileReader(file + "\个人信息.txt");
                    int i = 0;
                    try {
                        while ((i = fr.read()) != -1) {
                            str += (char) i;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                str += "
    ";
    
            }
            return str;
        }
    
        @Override
        public String findByage(String age) {
            String str = "";
            File f = new File("D:\RCGLXT\");
            File[] namelist = f.listFiles();
            for (File file : namelist) {
                String s = "";
                try {
                    FileReader fr = new FileReader(file + "\个人信息.txt");
                    int i = 0;
                    try {
                        while ((i = fr.read()) != -1) {
                            s += ((char) i);
                        }
                        if (s.indexOf(age) != -1) {
                            str += s;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
    
            }
            return str;
        }
    
        @Override
        public String findByaim(String aim) {
            String str = "";
            File f = new File("D:\RCGLXT\");
            File[] namelist = f.listFiles();
            for (File file : namelist) {
                String s = "";
                try {
                    FileReader fr = new FileReader(file + "\个人信息.txt");
                    int i = 0;
                    try {
                        while ((i = fr.read()) != -1) {
                            s += ((char) i);
                        }
                        if (s.indexOf(aim) != -1) {
                            str += s;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
    
            }
            return str;
        }
    
        @Override
        public String findListJava() {
            String str = "";
            File f = new File("D:\RCGLXT\");
            File[] namelist = f.listFiles();
            for (File file : namelist) {
                String s = "";
                try {
                    FileReader fr = new FileReader(file + "\个人信息.txt");
                    int i = 0;
                    try {
                        while ((i = fr.read()) != -1) {
                            s += ((char) i);
                        }
                        if (s.indexOf("java") != -1) {
                            str += s;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
    
            }
            return str;
        }
    
    package entity;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class Information {
        private String name;
        private String sex;
        private String age;
        private String aim;
        private String school;
        private String list;
        public Information(String name, String sex, String age, String aim, String school, String list) {
            super();
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.aim = aim;
            this.school = school;
            this.list = list;
        }
        /**
         * @return the name
         */
        public final String getName() {
            return name;
        }
        /**
         * @param name the name to set
         */
        public final void setName(String name) {
            this.name = name;
        }
        /**
         * @return the sex
         */
        public final String getSex() {
            return sex;
        }
        /**
         * @param sex the sex to set
         */
        public final void setSex(String sex) {
            this.sex = sex;
        }
        /**
         * @return the age
         */
        public final String getAge() {
            return age;
        }
        /**
         * @param age the age to set
         */
        public final void setAge(String age) {
            this.age = age;
        }
        /**
         * @return the aim
         */
        public final String getAim() {
            return aim;
        }
        /**
         * @param aim the aim to set
         */
        public final void setAim(String aim) {
            this.aim = aim;
        }
        /**
         * @return the school
         */
        public final String getSchool() {
            return school;
        }
        /**
         * @param school the school to set
         */
        public final void setSchool(String school) {
            this.school = school;
        }
        /**
         * @return the list
         */
        public final String getList() {
            return list;
        }
        /**
         * @param list the list to set
         */
        public final void setList(String list) {
            this.list = list;
        }
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "Information [name=" + name + ", sex=" + sex + ", age=" + age + ", aim=" + aim + ", school=" + school
                    + ", list=" + list + "]";
        }
        
        
    }
    package service;
    
    
    public interface JieKou {
        public void addInformation(String name, String sex, String age, String aim, String school, String list, String consume);
        public String findInformation();
        public String findByage(String age);
        public String findByaim(String aim);
        public String findListJava();
        public String findConsume(String name);
        
    }
    package controller;
    
    import java.util.ArrayList;
    
    import entity.Consume;
    import entity.Hunter;
    
    public class Test {
    
        public static void main(String[] args) {
            ArrayList<Consume> informations=new ArrayList<Consume>();
            Hunter hunter=new Hunter("京东", "北京");
            hunter.addInformation("张三", "女", "12", "计算机", "清华", "java", "简历1");
            hunter.addInformation("李四", "男", "22", "会计", "北大", "c", "简历2");
            System.out.println("查询全部信息:
    "+hunter.findInformation());
            System.out.println();
            System.out.println("根据年龄查询:
    "+hunter.findByage("12"));
            System.out.println();
            System.out.println("根据专业查询:
    "+hunter.findByaim("会计"));
            System.out.println();
            System.out.println("技能是Java查询:
    "+hunter.findListJava());
            System.out.println();
            System.out.println("查询人物简历:
    "+hunter.findConsume("李四"));
            
            
        }
    
    }
        public String findConsume(String name) {
            String str = "";
            File f = new File("D:\RCGLXT\");
            File[] namelist = f.listFiles();
            for (File file : namelist) {
                if (file.getName().equals(name)) {
                    try {
                        FileReader fr = new FileReader("D:\RCGLXT\" + name + "\个人介绍.txt");
                        String s = "";
                        int i = 0;
                        try {
                            while ((i = fr.read()) != -1) {
                                s += (char) i;
                            }
                            str += s;
    
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
            return str;
        }
    
    }
  • 相关阅读:
    在应用程序中利用Jena API处理OWL本体
    Encoded vs Literal, RPC vs Document
    DWR、XMLHTTP、XMLRPC和Flex
    北京的第一场雪
    让IE浏览器提示下载或直接打开word文档
    色拉英语第一集第一幕:记得说“请”
    色拉英语第一集第三幕:凯文在家吗?
    30天敏捷结果(30):提升敏捷结果
    生活:兔年春节家庭寻宝习俗
    敏捷个人:2011/1/26聊天记录(沟通、优势)
  • 原文地址:https://www.cnblogs.com/lumc5/p/15177705.html
Copyright © 2020-2023  润新知