1.设计一个单例类Boss,有姓名,性别,年龄三个属性,有自我介绍的方法display();
2.设计一个方法,将一个未知字符串str1中的数字全部提取出来,组成一个新的字符串str,然后将str2倒叙成str3,最后把str3作为方法的返回值;
3.将D:\hello.png文件复制到E:\hello目录下,先判断E:\hello是否存在,若存在直接将D:\hello.png复制,若不存在先创建目录
4.设计一个Student类,有姓名,年龄,性别三个私有属性,在测试类中创建5个Student类的对象,将这些对象写入到D:\StudentInfo.txt文件中,然后再从文件中读取出来,将这些学生的信息打印在控制台上。

解决方案 »

  1.   

    1./** 懒汉式 */
    public class Boss{
        private static String name;
        private static String gender;
        private static int age;
        private static Boss boss = null;        private Boss(){}
        private Boss(String name, String gender, int age){}
       
        public static Boss getInstance(String name, String gender, int age){
            if(boss==null){
                boss = new Boss(name, gender, age);
            }
            return boss;
        }
    }/** 饿汉式 */
    public class Boss{
        private static String name;
        private static String gender;
        private static int age;
        private static Boss boss = new Boss(name, gender, age);
      
        private Boss(){}
        private Boss(String name, String gender, int age){}        /** 因为在初始化时没有指定boss的姓名、性别和年龄,所以用setter方法对外提供修改器接口 */
        public void setName(String name){boss.name = name}
        public void setGender(String gender){boss.gender = gender}
        public void setAge(int age){boss.age = age}    public static Boss getInstance(){
            return boss;
        }
    }  ======================================
    2.HINT:判断单个字符是不是number的方法:isDigit()(先把str类型转换为char[]类型),因为字符串长度不确定,考虑使用StringBuilder,该方法最后返回String类型。(另,StringBuilder有reverse方法)。========================================
    3. HINT:创建File对象,try-catch判断是否抛出FileNotFoundException;复制文件用FileWriter(+BufferedReader)、FileWriter(+BufferedWriter)配合使用。
    ========================================
    4. ObjectOutputStream
      

  2.   

    少了三个分号,在setter方法那里(自己补上。