• 9(补)


    复制代码
    package Hzy;
    
    public class Circle {
        private double radius;
    
        public Circle(double radius) {
            this.radius = radius;
        }
    
        public Circle() {
            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 Hzy;
    
    public class DemoCircle {
        public static void main(String[] args) {
            Circle circle1=new Circle();
            double area=circle1.getArea();
            System.out.println(area);
            Circle circle2=new Circle(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 Hzy;
    
    public class SimpleCircle {
        private double radius;
        public SimpleCircle() {
            this.radius=1;
        }
        public SimpleCircle(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) {
            SimpleCircle cir1=new SimpleCircle();
            System.out.println("The area of the circle of radius "+cir1.radius+" is "+cir1.getArea());
            SimpleCircle cir2=new SimpleCircle(10);
            System.out.println("The area of the circle of radius "+cir2.radius+" is "+cir2.getArea());
        }
    }
    复制代码

    复制代码
    package Hzy;
    
    public class TV {
        public int channel=1;
        public int volumeLevel=1;
        public boolean on=false;
        
        public TV() {
            
        }
        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 Hzy;
    
    public class TestTV {
        public static void main(String[] args) {
          TV tv1=new TV();
          tv1.turnOn();
         tv1.setChannel(30);
          tv1.setVolumeLevel(3);
          
          TV tv2=new TV();
          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);
          
          
      }
    
    }
    复制代码

  • 相关阅读:
    <audio> 标签简介
    <sessionState>
    为 IIS 7.0 配置 <system.webServer>
    Litepal 数据库操作框架的使用 (火)
    Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(4)
    【iOS开发-55】图片轮播案例:scrollView的分页、滚动栏、利用代理控制定时器和Page Control以及多线程问题
    小白学react之网页获取微信用户信息
    HTML5游戏实战(1):50行代码实现正面跑酷游戏
    浮动、定位
    Tomcat7.0源代码分析——启动与停止服务原理
  • 原文地址:https://www.cnblogs.com/777lixiaohui/p/8058029.html
Copyright © 2020-2023  润新知