isTriangle=true;
}
}
returnisTriangle;
}
/**
*Checkthetypeoftriangle
*
*Consistsof"Illegal","Regular","Scalene","Isosceles"
*/
publicStringgetType(Triangletriangle){
StringstrType="Illegal";
if(isTriangle(triangle)){
//IsRegular
if(triangle.lborderA==triangle.lborderB
&&triangle.lborderB==triangle.lborderC){
strType="Regular";
}
//Ifscalene
elseif((triangle.lborderA!
=triangle.lborderB)
&&(triangle.lborderB!
=triangle.lborderC)
&&(triangle.lborderA!
=triangle.lborderC)){
strType="Scalene";
}
//ifisosceles
else{
strType="Isosceles";
}
}
returnstrType;
}
/**
*calculatethediffbetweenborders
*
**/
publiclongdiffOfBorders(longa,longb){
return(a>b)?
(a-b):
(b-a);
}
/**
*getlengthofborders
*/
publiclong[]getBorders(){
long[]borders=newlong[3];
borders[0]=this.lborderA;
borders[1]=this.lborderB;
borders[2]=this.lborderC;
returnborders;
}
}
2.软件工具
Eclipse
3.测试代码
题目
(1)
importorg.junit.After;
importorg.junit.Before;
importorg.junit.Test;
importorg.junit.Assert;
publicclassBinaryHeapTest{
@Before
publicvoidsetUp()throwsException{
}
@After
publicvoidtearDown()throwsException{
}
@Test
publicvoidtest(){
BinaryHeapheap1=newBinaryHeap(1024);
for(inti=1024;i>0;i--){
try{
heap1.insert(i);
}catch(Overflowe){
Assert.fail(e.