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

Problem2DrawShapesYouaresupposedtodraw3kindsofshape(rectangle,isoscelestriangle(等腰三角形... 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)

\
展开
 我来答
l3130y
2008-10-09 · TA获得超过951个赞
知道小有建树答主
回答量:547
采纳率:0%
帮助的人:547万
展开全部
这是等腰三角形,矩形,和菱形,后面的没看明白你的要求啊
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;}}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式