Java面向对象练习(2) (2024.7.11)
创始人
2025-01-11 05:37:55
0

        圆类

package area20240711;  public class Circle extends Picture{     private double r;     private final double PI = 3.1415926;      public Circle(){}      public Circle(double r) {         this.r = r;     }      public double getR() {         return r;     }      public void setR(double r) {         this.r = r;     }      public double getPI() {         return PI;     }      @Override     public double length() {         return 2 * PI * this.r;     }      @Override     public double area() {         return this.r * this.r * PI;     } } 

        图形类

package area20240711;  public abstract class Picture {     public abstract double length();     public abstract double area(); } 

        矩形类

package area20240711;  public class Rectangle extends Picture{     private double length;     private double width;      public Rectangle(){}      public Rectangle(double length, double width) {         this.length = length;         this.width = width;     }      public double getLength() {         return length;     }      public void setLength(double length) {         this.length = length;     }      public double getWidth() {         return width;     }      public void setWidth(double width) {         this.width = width;     }      @Override     public double length() {         return 2.0 * (this.length + this.width);     }      @Override     public double area() {         return this.length * this.width * 1.0;     } } 

        测试

package area20240711; import java.util.Scanner; public class AreaTest {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         // 创建一个矩形         Rectangle rtg = creatRectangle();         System.out.println("长为" + rtg.getLength() + "宽为" + rtg.getWidth()         + "的矩形的周长是" + rtg.length());         System.out.println("长为" + rtg.getLength() + "宽为" + rtg.getWidth()         + "的矩形的面积是" + rtg.area());          // 创建一个圆形         Circle c = creatCircle();         System.out.println("半径为" + c.getR() + "圆的周长是" + c.length());         System.out.println("半径为" + c.getR() + "圆的面积是" + c.area());       }      public static Rectangle creatRectangle () {         Scanner sc = new Scanner(System.in);         System.out.println("请输入矩形的长");         double length = sc.nextDouble();         System.out.println("请输入矩形的宽");         double width = sc.nextDouble();         return new Rectangle(length, width);     }      public static Circle creatCircle() {         Scanner sc = new Scanner(System.in);         System.out.println("请输入圆形的半径");         double r = sc.nextDouble();         return new Circle(r);     } } 

 

 

 

相关内容

热门资讯

来临!hhpoker辅助器视频... 来临!hhpoker辅助器视频,wepoker辅助工具,一贯确实有挂(了解有挂)1、很好的工具软件,...
围绕透视问题!德普之星有辅助软... 围绕透视问题!德普之星有辅助软件吗,德州来玩辅助器,一贯真的是有挂(有人有挂)小薇(辅助器软件下载)...
第三方插件!aa poker辅... 第三方插件!aa poker辅助,xpoker辅助,一贯存在有挂(有挂助手);1、aa poker辅...
随着!德州局怎么透视,uupo... 随着!德州局怎么透视,uupoker有透视吗,总是是有挂(有挂分享)该软件可以轻松地帮助玩家将德州局...
最新消息!wepoker透视脚... 最新消息!wepoker透视脚本苹果版,hhpoker透视脚本,真是确实有挂(有挂规律)wepoke...
2026版软件!wepoker... 2026版软件!wepoker免费脚本咨询,wepoker免费透视,切实真的有挂(的确有挂)1、we...
2026版技巧!we-poke... 您好,we-poker有人玩吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
不少玩家反映!wepoker轻... 不少玩家反映!wepoker轻量版有透视吗,hhpoker透视脚本,一直确实有挂(有挂解惑)wepo...
现就发布提示!wepoker透... 现就发布提示!wepoker透视脚本免费app,wepoker软件靠谱么,好像确实有挂(有挂方式)1...
在玩家背景下!wepoker有... 在玩家背景下!wepoker有辅助器吗,wepoker养号规律,好像确实有挂(有人有挂);1、进入到...