1. 程式人生 > >11.06第九次、

11.06第九次、

private moc false 開始 2-2 the area 1.0 span ()

1——————————————————————————————————————

package GJS1;

public class GJS {
    private double radius;

    public GJS(double radius) {
        this.radius = radius;
    }

    public GJS() {
        this.radius = 1;
    }

    public double getArea() {
        return radius * radius * Math.PI;

    }

    
public double getPerimeter() { return 2 * Math.PI * radius; } public void setRadius(double newRadius) { this.radius=newRadius; } }
package GJS1;

public class DemoCircle {
    public static void main(String[] args) {
        GJS circle1=new GJS();
        double area=circle1.getArea();
        System.out.println(area);
        GJS circle2
=new GJS(10); System.out.println(circle2.getArea()); System.out.println(circle1.getPerimeter()); System.out.println(circle2.getPerimeter()); double ridius=10; double areaCircle=Math.PI*ridius*ridius; System.out.println(areaCircle); circle2.setRadius(
5); System.out.println(circle2.getArea()); } }

技術分享圖片

2——————————————————————————————————————————————————————

package GJS1;

public class GJS {

    private double radius;
    public GJS() {
        this.radius=1;
    }
    public GJS(double radius){
        this.radius=radius;
    }
    public double getArea() {
        // TODO Auto-generated method stub
        return Math.PI*radius*radius;
    }
    public double getPerimeter() {
        return 2*Math.PI*radius;
    }
    
    public static void main(String[] args) {
        GJS cir1=new GJS();
        System.out.println("The area of the circle of radius "+cir1.radius+" is "+cir1.getArea());
        GJS cir2=new GJS(10);
        System.out.println("The area of the circle of radius "+cir2.radius+" is "+cir2.getArea());
    }
}

技術分享圖片

3———————————————————————————————————————————————————————————

package GJS1;

public class Z {
    public int channel=1;
    public int volumeLevel=1;
    public boolean on=false;
    
    public Z() {
        
    }
    public void turnOn() {
        on =true;
        System.out.println("電視機已經打開了。");
    }
    public void turnOff() {
        on=false;
        System.out.println("電視機已經關閉了。");
    }
    public int getChannel() {
        return channel;
    }
    public void setChannel(int channel) {
        if(on) {
            System.out.println("電視機已開,可以開始調臺了。");
            if(channel>=1&&channel<=120) {
                this.channel = channel;
                System.out.println("頻道已經調到 "+channel+" 臺");
            }else {
                System.out.println("你要調的頻道不存在。");
            }
        }else {
            System.out.println("電視機關著的時候是不能調臺的");
        }
    }
    public int getVolumeLevel() {
        return volumeLevel;
    }
    public void setVolumeLevel(int volumeLevel) {
        if(on) {
            System.out.println("電視機已開,聲音大小可調了");
            if(volumeLevel>=1&&volumeLevel<=7) {
                this.volumeLevel = volumeLevel;
                System.out.println("聲音的大小設置成了 "+volumeLevel+" 大小");
            }
        }else {
            System.out.println("電視機關著的時候是不能調聲音的");
        }
        
    }
    public void channelUp() {
        if(on&&channel<120) {
            channel++;
        }
    }
    public void channelDown() {
        if(on&&channel>1) {
            channel--;
        }
    }
    public void volumeUp() {
        if(on&&volumeLevel<7) {
            volumeLevel++;
        }
    }
    public void volumeDown() {
        if(on&&volumeLevel>1) {
            volumeLevel--;
        }
    }
    
    
}
package GJS1;

public class GJS {

    public static void main(String[] args) {
//        TV tv1=new TV();
//        tv1.turnOff();
//        tv1.setChannel(30);
//        tv1.setVolumeLevel(3);
        
        Z tv2=new Z();
        tv2.turnOn();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.channelUp();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.channelUp();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.channelUp();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.volumeUp();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.volumeUp();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        tv2.volumeUp();
        System.out.println("TV2‘s channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
        
        
    }

}

技術分享圖片

11.06第九次、