1. 程式人生 > >Java 2017.11.06 楊浩寧作業(1)

Java 2017.11.06 楊浩寧作業(1)

序號 true test import col util getch width ==

package top.hyself;

public class Test_1106 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        TestDemo circle1 = new TestDemo();
        double area=circle1.getArea();
        System.out.println(area);
        TestDemo circle2=new TestDemo(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()); } }
package top.hyself;

public class TestDemo {
    private double radius;
    
    public TestDemo(double
radius) { this.radius = radius; } public TestDemo() { this.radius = 1.0; } public double getArea() { return Math.PI * radius * radius; } public double getPerimeter() { return 2 * Math.PI * radius; } public void setRadius(double
newRadius) { this.radius = newRadius; } }

技術分享

package top.hyself;

public class Test_1106 {
    private double radius;
    
    public Test_1106(double radius) {
        this.radius = radius;
    }
    public Test_1106() {
        this.radius = 1.0;
    }
    public double getArea() {
        return Math.PI * radius * radius;
    }
    public double getPerimeter() {
        return 2 * Math.PI * radius;
    }
    public void setRadius(double newRadius) {
        this.radius = newRadius;
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Test_1106 circle1 = new Test_1106();
        double area=circle1.getArea();
        System.out.println(area);
        Test_1106 circle2=new Test_1106(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());
    }

}


package top.hyself;

public class $TV {
    //Init
    public int channel = 1;
    public int volume = 1;
    public boolean power = false;
    
    public void powerOn() {
        power = true;
        System.out.println("歡迎使用$TV,電視機已啟動!");
    }
    public void powerOff() {
        power = false;
        System.out.println("關機中...");
        System.out.println("已關機!");
    }
    public int getChannel() {
        return channel;
    }
    public void setChannel(int channel) {
        if(power) {
            if(channel >= 1 && channel <= 100) {
                this.channel = channel;
                System.out.println("正在收看第:" + channel +" 頻道");
            }else {
                System.out.println("您並未購買此頻道信號!");
            }
        }else {
            System.out.println("Error! 錯誤404,請檢查您的電視是否處於開機狀態或故障中!");
        }
    }
    public void channelUp() {
        if(power  && channel < 100)
            channel++;
        else System.out.println("不能再往上了!");
    }
    public void channelDown() {
        if(power  && channel > 1)
            channel--;
        else System.out.println("電視機也是有底限的!");
    }
    public void volumeUp() {
        if(power && volume < 10) {
            volume++;
            System.out.println("當前音量為:" + volume + "%!");
        }else System.out.println("不能再往上了!");
    }
    public void volumeDown() {
        if(power && volume > 0) {
            volume--;
            if(volume == 0)
                System.out.println("電視機已靜音!");
        }else System.out.println("電視機也是有底限的!");
            
    }

}
package top.hyself;
import java.util.Scanner;

import org.omg.CORBA.portable.ValueOutputStream;
public class TV$Demo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in);
        $TV hyper = new $TV();
        hyper.powerOn();
        System.out.print("手動輸入頻道序號:");
        int temp = Integer.valueOf(scan.nextLine());;
        hyper.setChannel(temp);
        hyper.getChannel();
        hyper.volumeDown();hyper.volumeDown();
    }

}

技術分享

Java 2017.11.06 楊浩寧作業(1)