问题描述
关于接口的那段代码看不懂谁帮我注释一下这是老师给我们的程序importjava.awt.Rectangle;/**Computestheaverageofasetofdatavalues.*/classDataSet{/**Constructsanemptydatasetwithagivenmeasurer.@paramaMeasurerthemeasurerthatisusedtomeasuredatavalues*/publicDataSet(MeasureraMeasurer){sum=0;count=0;maximum=null;measurer=aMeasurer;}/**Addsadatavaluetothedataset.@paramxadatavalue*/publicvoidadd(Objectx){sum=sum+measurer.measure(x);if(count==0||measurer.measure(maximum)<measurer.measure(x))maximum=x;count++;}/**Getstheaverageoftheaddeddata.@returntheaverageor0ifnodatahasbeenadded*/publicdoublegetAverage(){if(count==0)return0;elsereturnsum/count;}/**Getsthelargestoftheaddeddata.@returnthemaximumor0ifnodatahasbeenadded*/publicObjectgetMaximum(){returnmaximum;}privatedoublesum;privateObjectmaximum;privateintcount;privateMeasurermeasurer;}/**ThisprogramdemonstratestheuseofaMeasurer.*/publicclassDataSetTest{publicstaticvoidmain(String[]args){Measurerm=newRectangleMeasurer();DataSetdata=newDataSet(m);data.add(newRectangle(5,10,20,30));data.add(newRectangle(10,20,30,40));data.add(newRectangle(20,30,5,10));System.out.println("Averagearea="+data.getAverage());Rectanglemax=(Rectangle)data.getMaximum();System.out.println("Maximumarearectangle="+max);}}/**Describesanyclasswhoseobjectscanmeasureotherobjects.*/interfaceMeasurer{/**Computesthemeasureofanobject.@paramanObjecttheobjecttobemeasured@returnthemeasure*/doublemeasure(ObjectanObject);}/**Objectsofthisclassmeasurerectanglesbyarea.*/classRectangleMeasurerimplementsMeasurer{publicdoublemeasure(ObjectanObject){RectangleaRectangle=(Rectangle)anObject;doublearea=aRectangle.getWidth()*aRectangle.getHeight();returnarea;}}
解决方案
解决方案二:
字面解释,测量接口。上面的代码用来计算传入对象的面积。
解决方案三:
上面不是用注解撒。
解决方案四:
注释写的都很明白啊要学会看英文注释一般规范点的软件公司的代码都是用英文写注释滴