JAVA练习9

复制代码
public class Circle {
    private double radius;
    
    public Circle(){
        this.radius=1;
    }
    public Circle(double radius){
        this.radius=radius;
    }
    
    public double getArea(){
        return radius*radius*Math.PI;
        
    }
    public double getPerimeter(){
        return 2*radius*Math.PI;
        
    }
    public void setRadius(double newRadius) {
        this.radius=newRadius;
    }
}
复制代码

 

复制代码
public class Democirle {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Circle circle1=new Circle();
        System.out.println(circle1.getArea());
        Circle circle2=new Circle(10);
        System.out.println(circle2.getArea());
        Circle circle3=new Circle();
        System.out.println(circle3.getPerimeter());
        Circle circle4=new Circle(10);
        System.out.println(circle4.getPerimeter());
        circle2.setRadius(2);
        System.out.println(circle2.getPerimeter());

    }

}
复制代码

 

 

 

复制代码
public class Simplecircle {
private double radius;
    
    public Simplecircle(){
        this.radius=1;
    }
    public Simplecircle(double radius){
        this.radius=radius;
    }
    
    public double getArea(){
        return radius*radius*Math.PI;
        
    }
    public double getPerimeter(){
        return 2*radius*Math.PI;
        
    }
    public void setRadius(double newRadius) {
        this.radius=newRadius;
    }
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Circle circle1=new Circle();
        System.out.println(circle1.getArea());
        Circle circle2=new Circle(5);
        System.out.println(circle2.getArea());
        Circle circle3=new Circle();
        System.out.println(circle3.getPerimeter());
        Circle circle4=new Circle(10);
        System.out.println(circle4.getPerimeter());
        circle2.setRadius(2);
        System.out.println(circle2.getPerimeter());

    }

}
复制代码

 

复制代码
public class TestTV {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        TV tv1=new TV();
        tv1.turnOn();
        tv1.setChannel(6);
        tv1.setChannel(121);
        tv1.setVolumeLevel(5);
        tv1.setVolumeLevel(9);
        
        //tv1.turnOff();
        //tv1.setChannel(6);
        //tv1.setVolumeLevel(5);
        
        TV tv2=new TV();
        tv2.turnOn();
        System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.channelUp();
        tv2.volumeUp();
        System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);

    }

}
复制代码

 
 
 
posted @ 2017-11-20 10:18  戒指和书,我看到了我想要的幸福  阅读(216)  评论(0编辑  收藏  举报