码迷,mamicode.com
首页 > 编程语言 > 详细

大数据Java基础第七天作业

时间:2016-05-12 00:09:33      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:java   内部类   匿名类   jar打包   

第一题:
interface IWhite{
    public void white();
}

interface IRich{
    public void rich();
}

interface IBeauti{
    public void beauti();
}

interface IWRB extends IWhite,IRich,IBeauti{};

class RichMan{
    public void toMarry(IWRB ws){
        ws.white();
        ws.rich();
        ws.beauti();
    }
}

class Marry{
    public static void main(String[] args){
        RichMan rm = new RichMan();
        rm.toMarry(new IWRB(){
            public void white(){
                System.out.println("I‘m white !");
            }

            public void rich(){
                System.out.println("I‘m rich !");
            }

            public void beauti(){
                System.out.println("I‘m beauti !");
            }
        });
    }
}
第二题:
class Trianle{
    private int a;
    private int b;
    private int c;

    public void setEdgeA(int edge){
        this.a = edge;
    }

    public void setEdgeB(int edge){
        this.b = edge;
    }

    public void setEdgeC(int edge){
        this.c = edge;
    }

    public void check() throws Exception{
        int max;
        int other;
        if(a >= b && a >= c){
            max = a;
            other = b + c;
        }else if(b >= a && b >= c){
            max = b;
            other = a + c;
        }else{
            max = c;
            other = a + b;
        }
        if(max > other){
            throw new Exception("三角形边的长度设置错误!");
        }else{
            System.out.println("是三角形!");
        }
    }
}

class ThrowDemo{
    public static void main(String[] args){
        try{
            Trianle trianle = new Trianle();
            trianle.setEdgeA(20);
            trianle.setEdgeA(200);
            trianle.setEdgeC(200);
            trianle.check();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
第三题:
class InvalidParamExcetion extends Exception{
    public InvalidParamExcetion(String msg){
        super(msg);
        System.out.println(msg);
    }
}

class Person{
    private String birthday;
    
    public String getBirthday(){
        return birthday;
    }

    public void setBirthday(int year,int month,int day) throws InvalidParamExcetion{
        if(year < 1900 || year > 2016){
            throw new InvalidParamExcetion("年份不合适,不存在" + year + "月");
        }
        if(month < 1 || month > 12){
            throw new InvalidParamExcetion("月份不合适,不存在" + month + "月");
        }
        if(day < 1 || day > 31){
            throw new InvalidParamExcetion("日期不合适,不存在" + day + "日");
        }else{
            Boolean monday = (month == 1 || month == 3 || month == 5 || month == 8 || month == 10 || month == 12);
            if(monday && day != 31){
                throw new InvalidParamExcetion("日期不合适,不存在" + day + "日");
            }else if(month == 2 && day > 29){
                throw new InvalidParamExcetion("日期不合适,不存在" + day + "日");
            }else if(month == 2 && year % 4 != 0 && day == 29){
                throw new InvalidParamExcetion("日期不合适,不存在" + day + "日");
            }
        }
        birthday = "生日为:" + year + "年" + month + "月" + day + "日";
    }
}

class ThrowDemo{
    public static void main(String[] args){
        try{
            Person person = new Person();
            person.setBirthday(2016,2,10);
            System.out.println(person.getBirthday());
        }catch(InvalidParamExcetion e){
            e.printStackTrace();
        }
    }
}
第四题:
当前是在07目录下
1、创建pack.java文件
package a.b.c.d;
class Pack{
    public static void main(String[] args){
        System.out.println("hello world...");
    }
}
2、创建classes目录
3、编译 javac -d classes/ pack.java
4、打包 jar cvfe pack.jar a.b.c.d.Pack -C classes/ .
5、执行 java -jar pack.jar a.b.c.d.Pack
第五题:
1、创建08文件夹
2、cmd进入08文件下执行,java -jar pack.jar a.b.c.d.Pack


本文出自 “功不唐捐” 博客,请务必保留此出处http://senlinmin.blog.51cto.com/6400386/1772343

大数据Java基础第七天作业

标签:java   内部类   匿名类   jar打包   

原文地址:http://senlinmin.blog.51cto.com/6400386/1772343

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!