zoukankan      html  css  js  c++  java
  • Java作业-实验四

    Circle类

    package com.itcast.atd.demo05;
    
    public class Circle {
        private int radius;
    
        public Circle(){
        }
    
        public Circle(int r) {
            this.radius = r;
        }
    
        public int getRadius() {
            return radius;
        }
    
        public void setRadius(int r) {
            this.radius = r;
        }
    
        public double getPerimeter(){
            return radius*3.14*2;
        }
    
        public double getS(){
            return Math.pow(radius,2)*3.14;
        }
    
        public void disp(){
            System.out.println(radius);
            System.out.println(this.getPerimeter());
            System.out.println(this.getS());
        }
    }

    Cylinder类

    package com.itcast.atd.demo05;
    
    public class Cylinder extends Circle{
        private double height;
    
        public Cylinder(double height) {
            this.height = height;
        }
    
        public Cylinder(int r, double height) {
            super(r);//使用super调用父类中的构造方法
            this.height = height;
        }
    
        public double getHeight() {
            return height;
        }
    
        public void setHeight(double height) {
            this.height = height;
        }
    
        public double getVol(){
            return super.getS()*height;
        }
    
        public void dispVol(){
            System.out.println(this.getVol());
        }
    }

    TEST

    package com.itcast.atd.demo05;

    public class Test {
    public static void main(String[] args) {
            Cylinder cylinder = new Cylinder(2,4);
            System.out.println(cylinder.getVol());
        }
    }

    题目链接:https://viewer.mosoteach.cn/viewer?token=152bd977ea40b78b8fb396cfbbb1a805

    总结:学习起来之后,这题目很简单。相关学习情况我会发随笔记录,欢迎大家阅读。

  • 相关阅读:
    单片机编程积累算法
    关于GSM基站定位
    GSM模块fibocom G510使用记录
    指爱 打字比赛记录
    硬件和软件工程师
    GPS模块启动模式说明
    阻容降压电路分析
    饮水机电路-工作剖析
    跑步,去
    day01 IT知识架构,操作系统简介
  • 原文地址:https://www.cnblogs.com/changanshisanzhao/p/11607256.html
Copyright © 2011-2022 走看看