zoukankan      html  css  js  c++  java
  • Java 2017.11.06 杨浩宁作业(1)

    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();
        }
    
    }

  • 相关阅读:
    JavaScript 深入之从原型到原型链
    js重写内置的call、apply、bind
    js中flat方法的实现原理
    【我的物联网成长记6】由浅入深了解NB-IoT【华为云技术分享】
    GO富集分析示例【华为云技术分享】
    华为“方舟编译器”到底是啥?一文看懂TA如何让手机性能再突破【华为云技术分享】
    无码系列-7-代码的语文修养_上篇【华为云技术分享】
    机器学习笔记(一)----基本概念【华为云技术分享】
    性能达到原生 MySQL 七倍,华为云 Taurus 技术解读【华为云技术分享】
    【立即报名】人脸情绪识别案例分享【华为云技术分享】
  • 原文地址:https://www.cnblogs.com/Hyself/p/7811324.html
Copyright © 2011-2022 走看看