From 36a933cc7d0bcb1a8697e703a5a07888dec1c425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BF=8A=E4=BC=9F?= <2421084001@qq.com> Date: Wed, 10 May 2023 23:53:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14\346\254\241\344\275\234\344\270\232.md" | 115 ++++++++++++++++++ ...1\346\254\241\344\275\234\344\270\232.txt" | 29 +++++ 2 files changed, 144 insertions(+) create mode 100644 "12 \346\236\227\344\277\212\344\274\237/0506 \347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232.md" create mode 100644 "12 \346\236\227\344\277\212\344\274\237/0507 \347\254\254\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232.txt" diff --git "a/12 \346\236\227\344\277\212\344\274\237/0506 \347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232.md" "b/12 \346\236\227\344\277\212\344\274\237/0506 \347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000..f1f46af --- /dev/null +++ "b/12 \346\236\227\344\277\212\344\274\237/0506 \347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,115 @@ +public class Graphic { + public double area(){ + return 0.0; + } + public double perimeter(){ + return 0.0; + } + public String getInfo(){ + String Graphic=null; + return Graphic; + } +} +class Circle extends Graphic{ + private double radivs; + + public double getRadivs() { + return radivs; + } + + public void setRadivs(double radivs) { + this.radivs = radivs; + } + + public Circle() { + } + + public Circle(double radivs) { + this.radivs = radivs; + } + + @Override + public double area() { + return Math.PI*radivs*radivs; + } + + @Override + public double perimeter() { + return Math.PI*2*radivs; + } + + @Override + public String getInfo() { + return "面积:"+Math.PI*radivs*radivs+"周长:"+Math.PI*2*radivs+"半径:"+this.radivs; + } +} +class Rectangle extends Graphic{ + private double length; + private double width; + + public Rectangle(double length, double width) { + this.length = length; + this.width = width; + } + + public Rectangle() { + } + + 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 area() { + return length*width; + } + + @Override + public double perimeter() { + return (length+width)*2; + } + + @Override + public String getInfo() { + return "长:"+length+"宽:"+width+ "面积:"+length*width+"周长:"+(length+width)*2; + } +} +``` + +## 测试类 + +``` java +public class Test { + public static void main(String[] args) { + Graphic c = new Circle(5.5); + double a=c.area(); + double p = c.perimeter(); + System.out.println(c.area()); + System.out.println(c.perimeter()); + System.out.println(c.getInfo()); + Graphic R = new Rectangle(12,5); + double A = R.area(); + double P = R.perimeter(); + System.out.println(R.getInfo()); + System.out.println("圆的面积大于矩形的面积是:"+fanf(a, A)); + System.out.println("圆的周长大于矩形的周长是:"+fanf2(p, P)); + } + public static boolean fanf(double a,double A){ + return a>A; + } + public static boolean fanf2(double p,Double P){ + return p>P; + } +} diff --git "a/12 \346\236\227\344\277\212\344\274\237/0507 \347\254\254\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232.txt" "b/12 \346\236\227\344\277\212\344\274\237/0507 \347\254\254\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232.txt" new file mode 100644 index 0000000..81113be --- /dev/null +++ "b/12 \346\236\227\344\277\212\344\274\237/0507 \347\254\254\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232.txt" @@ -0,0 +1,29 @@ +import java.sql.SQLOutput; +import java.util.Scanner; + +public class Main { + public static void main(String[] args){ + while (true) { + + try { + Scanner sc = new Scanner(System.in); + System.out.println("请输入整数1"); + int I1 = sc.nextInt(); + Scanner s = new Scanner(System.in); + System.out.println("请输入整数2"); + int I2 = sc.nextInt(); + int num=0; + if (I1>0 && I2>0){ + num=num+I1+I2; + System.out.println("输入值为"+num); + break; + }else if (I1<0 && I2<0){ + System.out.println("输入数字不能为负"); + break; + } + } catch (Exception e) { + System.out.println("输入类型错误"); + } + } + } +} \ No newline at end of file -- Gitee