JAVA简单编程题目,求助谢谢了~

Problem 2 Draw Shapes
You are supposed to draw 3 kinds of shape (rectangle, isosceles triangle (等腰三角形), and diamond) using the input character.
Input
You should first input the type of the shape, 'r' for rectangle, ’t’ for triangle, 'd' for diamond, and 'q' for quit.
For rectangle, you should then input the height and the width; for triangle and diamond, you need only input the height, and you yourself calculate its width in each line.
Last, you should enter the character which will fulfill your shape
Output
The shape.
Sample Input
1) r 3 5 *
2) t 6 \
3) d 9 =
4) d 10 -
5) q
Sample Output
1)

*****
*****
*****
2)

\

这是等腰三角形,矩形,和菱形,后面的没看明白你的要求啊
class Trangle //等腰三角形
{
double sideA,sideB,sideC,area,length;
boolean boo;
public Trangle(double a,double b,double c)
{
//【代码1】 // 参数a, b, c分别赋值给sideA, sideB, sideC
this.sideA=a;this.sideB=b;this.sideC=c;
if((a+b>c&a+c>b&b+c>a)&&(a-b<c&a-c<b&b-c<a)&&(a==b||a==c||b==c)) //a, b, c构成等腰三角形的条件表达式
{
boo=true;
//【代码3】 // 给boo赋值
}
else
{
boo=false;
//【代码4】 // 给boo赋值
}
}
double getLength()
{
return sideA+sideB+sideC;
//【代码5】 // 方法体,要求计算出length的值并返回
}
public double getArea()
{
if(boo)
{
double p=(sideA+sideB+sideC)/2.0;
area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC)) ;
return area;
}
else
{
System.out.println("不是一个三角形,不能计算面积");
return 0;
}
}
public void setABC(double a,double b,double c)
{
this.sideA=a;this.sideB=b;this.sideC=c;
//【代码6】 // 参数a, b, c分别赋值给sideA, sideB, sideC
if((a+b>c&a+c>b&b+c>a)&(a-b<c&a-c<b&b-c<a)&&(a==b||a==c||b==c)) // a, b, c构成等腰三角形的条件表达式
{
boo=true;
//【代码8】 //给boo赋值。
}
else
{
boo=false;
//【代码9】 // 给boo赋值
}
}
}
class rectangle//矩形
{
double above,height;//长宽
public rectangle(double above,double height)
{this.above =above;
this.height =height;
}
double getLength() //返回周长
{
return above*2+height*2;
// 方法体,要求计算出length的值并返回
}
public double getArea()//返回面积
{return above*height;}
}
class diamond//菱形
{double above;//对角线
public diamond(double above)
{this.above =above;

}
double getLength() //返回周长
{
return above*2*1.414;
// 方法体,要求计算出length的值并返回
}
public double getArea()//返回面积
{return above*above/2;}}
温馨提示:答案为网友推荐,仅供参考
相似回答