欢迎来到天天文库
浏览记录
ID:31602821
大小:35.55 KB
页数:34页
时间:2019-01-15
《java语言程序设计基础篇第十版第十三章练习答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、01publicclassExercise13_01{publicstaticvoidmain(String[]args){TriangleNewtriangle=newTriangleNew(1,1.5,1);triangle.setColor("yellow");triangle.setFilled(true);System.out.println(triangle);System.out.println("Theareais"+triangle.getArea());System.out.println("Theperime
2、teris"+triangle.getPerimeter());System.out.println(triangle);}}classTriangleNewextendsGeometricObject{privatedoubleside1=1.0,side2=1.0,side3=1.0;/**Constructor*/publicTriangleNew(){}/**Constructor*/publicTriangleNew(doubleside1,doubleside2,doubleside3){this.side1=side
3、1;this.side2=side2;this.side3=side3;}/**ImplementtheabstractmethodfindAreainGeometricObject*/publicdoublegetArea(){doubles=(side1+side2+side3)/2;returnMath.sqrt(s*(s-side1)*(s-side2)*(s-side3));}/**ImplementtheabstractmethodfindCircumferencein*GeometricObject**/public
4、doublegetPerimeter(){returnside1+side2+side3;}@OverridepublicStringtoString(){//Implementittoreturnthethreesidesreturn"TriangleNew:side1="+side1+"side2="+side2+"side3="+side3;}}02importjava.util.ArrayList;publicclassExercise13_02{publicstaticvoidmain(String[]args){Arr
5、ayListlist=newArrayList();list.add(14);list.add(24);list.add(4);list.add(42);list.add(5);shuffle(list);for(inti=0;ilist){for(inti=0;i6、x=(int)(Math.random()*list.size());Numbertemp=list.get(i);list.set(i,list.get(index));list.set(index,temp);}}}03importjava.util.ArrayList;publicclassExercise13_03{publicstaticvoidmain(String[]args){ArrayListlist=newArrayList();list.add(14);list.add(24)7、;list.add(4);list.add(42);list.add(5);sort(list);for(inti=0;ilist){for(inti=0;i8、ntMinIndex=i;for(intj=i+1;jlist.get(j).doubleValue()){currentMin=list.get(j);c
6、x=(int)(Math.random()*list.size());Numbertemp=list.get(i);list.set(i,list.get(index));list.set(index,temp);}}}03importjava.util.ArrayList;publicclassExercise13_03{publicstaticvoidmain(String[]args){ArrayListlist=newArrayList();list.add(14);list.add(24)
7、;list.add(4);list.add(42);list.add(5);sort(list);for(inti=0;ilist){for(inti=0;i8、ntMinIndex=i;for(intj=i+1;jlist.get(j).doubleValue()){currentMin=list.get(j);c
8、ntMinIndex=i;for(intj=i+1;jlist.get(j).doubleValue()){currentMin=list.get(j);c
此文档下载收益归作者所有