欢迎来到天天文库
浏览记录
ID:40749616
大小:47.53 KB
页数:6页
时间:2019-08-07
《java求图形的面积和、周长》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验三实验报告实验名称求图形的面积和、周长和实验目的通过本次实验使学生掌握java语言对抽象类的定义、方法重写、多态等知识点的用法实验内容代码:importjava.util.Scanner;publicclassTsetShape{publicstaticdoublecalculateArea(MyShape[]s){doubleresult=0.0d;for(inti=0;i2、ape[]s){doubleresult=0.0d;for(inti=0;i3、em.in);System.out.println("");MyShape[]myShape=newMyShape[4];for(inti=0;i<5;i++){intn=scan.nextInt();}*/MyShape[]myShape={newSquare(8),newSquare(10),newCircle(8),newTriangle(8,6,6),newTriangle(10,10,10)};printAllShapse(myShape);System.out.println("面积和是:"+calculateArea(myShape));Sy4、stem.out.println("周长和是:"+calculateRound(myShape));};}abstractclassMyShape{privateStringname;publicMyShape(Stringname){this.name=name;}publicabstractdoublegetArea();publicabstractdoublegetRound();publicStringtoString(){return"""+name+"",面积是:"+this.getArea()+",周长是:"+this.getRound(5、);}}classCircleextendsMyShape{privatedoubler;publicCircle(doubler){super("圆形,半径是:"+r);this.r=r;}publicdoublegetArea(){returnMath.PI*r*r;}publicdoublegetRound(){return2*Math.PI*r;}}classSquareextendsMyShape{privatedoublea;publicSquare(doublea){super("正方形,边长是:"+a);this.a=a;}publicdo6、ublegetArea(){returna*a;}publicdoublegetRound(){return4*a;}}classTriangleextendsMyShape{//三角形privatedoublea;privatedoubleb;privatedoublec;publicTriangle(doublea,doubleb,doublec){super("三角形,三边是:"+a+","+b+","+c);this.a=a;this.b=b;this.c=c;}publicdoublegetArea(){doublep=(a+b+c)/2;dou7、bles=java.lang.Math.sqrt(p*(p-a)*(p-b)*(p-c));returns;}publicdoublegetRound(){returna+b+c;}}截图:实验心得:这次试验基本掌握了掌握java语言对抽象类的定义、方法重写、多态等知识点的用法,对方法重写有进一步认识,在这方面能力还欠缺应该继续努力掌握更多知识。
2、ape[]s){doubleresult=0.0d;for(inti=0;i3、em.in);System.out.println("");MyShape[]myShape=newMyShape[4];for(inti=0;i<5;i++){intn=scan.nextInt();}*/MyShape[]myShape={newSquare(8),newSquare(10),newCircle(8),newTriangle(8,6,6),newTriangle(10,10,10)};printAllShapse(myShape);System.out.println("面积和是:"+calculateArea(myShape));Sy4、stem.out.println("周长和是:"+calculateRound(myShape));};}abstractclassMyShape{privateStringname;publicMyShape(Stringname){this.name=name;}publicabstractdoublegetArea();publicabstractdoublegetRound();publicStringtoString(){return"""+name+"",面积是:"+this.getArea()+",周长是:"+this.getRound(5、);}}classCircleextendsMyShape{privatedoubler;publicCircle(doubler){super("圆形,半径是:"+r);this.r=r;}publicdoublegetArea(){returnMath.PI*r*r;}publicdoublegetRound(){return2*Math.PI*r;}}classSquareextendsMyShape{privatedoublea;publicSquare(doublea){super("正方形,边长是:"+a);this.a=a;}publicdo6、ublegetArea(){returna*a;}publicdoublegetRound(){return4*a;}}classTriangleextendsMyShape{//三角形privatedoublea;privatedoubleb;privatedoublec;publicTriangle(doublea,doubleb,doublec){super("三角形,三边是:"+a+","+b+","+c);this.a=a;this.b=b;this.c=c;}publicdoublegetArea(){doublep=(a+b+c)/2;dou7、bles=java.lang.Math.sqrt(p*(p-a)*(p-b)*(p-c));returns;}publicdoublegetRound(){returna+b+c;}}截图:实验心得:这次试验基本掌握了掌握java语言对抽象类的定义、方法重写、多态等知识点的用法,对方法重写有进一步认识,在这方面能力还欠缺应该继续努力掌握更多知识。
3、em.in);System.out.println("");MyShape[]myShape=newMyShape[4];for(inti=0;i<5;i++){intn=scan.nextInt();}*/MyShape[]myShape={newSquare(8),newSquare(10),newCircle(8),newTriangle(8,6,6),newTriangle(10,10,10)};printAllShapse(myShape);System.out.println("面积和是:"+calculateArea(myShape));Sy
4、stem.out.println("周长和是:"+calculateRound(myShape));};}abstractclassMyShape{privateStringname;publicMyShape(Stringname){this.name=name;}publicabstractdoublegetArea();publicabstractdoublegetRound();publicStringtoString(){return"""+name+"",面积是:"+this.getArea()+",周长是:"+this.getRound(
5、);}}classCircleextendsMyShape{privatedoubler;publicCircle(doubler){super("圆形,半径是:"+r);this.r=r;}publicdoublegetArea(){returnMath.PI*r*r;}publicdoublegetRound(){return2*Math.PI*r;}}classSquareextendsMyShape{privatedoublea;publicSquare(doublea){super("正方形,边长是:"+a);this.a=a;}publicdo
6、ublegetArea(){returna*a;}publicdoublegetRound(){return4*a;}}classTriangleextendsMyShape{//三角形privatedoublea;privatedoubleb;privatedoublec;publicTriangle(doublea,doubleb,doublec){super("三角形,三边是:"+a+","+b+","+c);this.a=a;this.b=b;this.c=c;}publicdoublegetArea(){doublep=(a+b+c)/2;dou
7、bles=java.lang.Math.sqrt(p*(p-a)*(p-b)*(p-c));returns;}publicdoublegetRound(){returna+b+c;}}截图:实验心得:这次试验基本掌握了掌握java语言对抽象类的定义、方法重写、多态等知识点的用法,对方法重写有进一步认识,在这方面能力还欠缺应该继续努力掌握更多知识。
此文档下载收益归作者所有