zoukankan      html  css  js  c++  java
  • 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);
    
        }
    
    }
    复制代码

     
     
  • 相关阅读:
    java常用IO流集合用法模板
    java根据概率生成数字
    从浏览器直接转跳到APP具体页面---(魔窗)MagicWindow使用教程
    java开源即时通讯软件服务端openfire源码构建
    还在繁琐的敲MVP接口和实现类吗,教你一秒搞定。
    手把手带你走进MVP +Dagger2 + DataBinding+ Rxjava+Retrofit 的世界
    poj3666(DP+离散化)
    poj3616(LIS简单变式)
    hdoj2859(矩阵DP)
    poj1088(记忆化搜索入门题)
  • 原文地址:https://www.cnblogs.com/qxc81518/p/7865108.html
Copyright © 2011-2022 走看看