用继承关系shape作为父类转子类,rectangle,cricle,triangle三个类计算面积和周长,最后测试为什么我的结果是0

How to Draw Rectangle, Circle and Basic Shape on PDF Page
&|&&&&|&&&&|&&
PDFill PDF Drawing:
Rectangle, Circle and Basic Shape Tool
(See Example
and Example )
You can use this tool to draw rectangle,
square, round corner, circle, ellipse, arc and pie, and more basic
shapes into PDF
More Basic Shape
Drawings include Isosceles Triangle, Right Triangle, Diamond, Pentagon,
Hexagon, Left Arrow, Right Arrow, Up Arrow, Down Arrow, 4-Point Star,
5-Point Star, 6-Point Star, Rounded Rectangular Callout, Oval Callout,
Cloud Callout, Heart, Lightning and Smiley Face.
change drawing’s Line Width, Dashed Style, Line Color, Fill
Color and Transparency.
1. Steps on how to draw a
Rectangle, Circle or
Basic Shape on PDF Page:
& Drawing &
Select Rectangle
or Basic Shape
or click Rectangle
or Basic Shape
Button in the
Click the Basic Types Button to
show the menu and then select a basic shape
Hold Left mouse button to create
an area of the required
size and then release it
2. Access the properties:
Click the Selection button
Click inside the line to highlight it and click
Properties Button
Or, click the line and double-click again
Or, Key F4
3. Set the properties:
Here is the list of the properties.
Line Weight
The thickness of the line.
Line Color
The color for the
Line Dashed
There are 8 Dashed Styles:
Solid, Round Dot, Square Dot, Dash, Dash Dot, Long Dash,
Long Dash Dot, Long Dash Dot Dot
Fill Color
The background
color inside the shape.
The rotation
degree from 3 clock relative to the shape center.
Transparency
The Transparency of the drawing
If set, it will be a
rectangle or square type
Corner Radius
If Set, the rectangle
will have a round corner with the radius
If set, it will be a
ellipse, circle type
If set, it will be not
full 360 degree circle/ellipse
An edge will be drawn.
Start Angle
degree from 3 Clock
Anticlockwise direction
Basic Shapes
Isosceles Triangle, Right Triangle, Diamond,
Pentagon, Hexagon, Left Arrow, Right Arrow, Up
Arrow, Down Arrow, 4-Point Star, 5-Point Star,
6-Point Star, Rounded Rectangular Callout, Oval
Callout, Cloud Callout, Heart, Lightning and Smiley
Position (Left, Right, Top, Bottom)
The X and Y
coordinate of the box to define the position of
the field.
Blend Mode
Rectangle or Circle. Please save into a new PDF to
see the blending effect.
will show on the Foreground or Background of the PDF
a PDF Layer name if it belongs to a PDF Layer. Make
it empty if it doesn't belong to a PDF Layer. See
details in .
Action: Add Link, Submit,
JavaScript and more ...
Set this field as default
If set, the new
object will have the same properties
as this one.
4. Screenshots:
Rectangle, Square, and Round Corner
Circle, Ellipse, Arc and Pie
More Basic Shapes
Copyright (C)
..& All rights reserved.1、编写一个Java应用程序,该程序包括3个类:Monkey类、People类和测试类。要求:
(1)Monkey类中有个public void speak()方法,在speak方法中输出“咿咿呀呀。。。。。。”的信息。
(2)People类是Monkey类的子类,在People类中重写方法speak,在speak方法中输出“小样的,不错嘛,会说话了!”的信息。
(3)在People类中新增方法void think(),在think方法中输出“别说话,认真思考!”的信息。
* Monkey 父类
package cn.yjlblog.
public class Monkey
public void speak()
System.out.println(&咿咿呀呀。。。。。。&);
* People 子类
package cn.yjlblog.
public class People extends Monkey
public void speak()
System.out.println(&小样的,不错嘛,会说话了!&);// TODO Auto-generated method stub
void think()
System.out.println(&别说话,认真思考!&);
* TestClass 测试类
package cn.yjlblog.
public class TestClass {
public static void main(String[] args) {
Monkey m = new Monkey();
m.speak();
Monkey p = new People();
p.speak();
//Monkey p1 = new People();//The method think() is undefined for the type Monkey
People p1 = new People();
p1.think();
2、按要求编写一个Java应用程序:
(1)定义一个类(Rectangle),描述一个矩形,包含有长、宽两种属性和计算面积的方法。
(2)定义一个类(Cuboid),继承自矩形类,同时该类描述长方体,具有长、宽、高属性和计算体积的方法。
(3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、宽、高,输出其底面积和体积。
* Rctangle 父类
package cn.yjlblog.
public class Rectangle
//生成set 和get 方法
public double getLength() {
public void setLength(double length) {
this.length =
public double getWidth() {
public void setWidth(double width) {
this.width =
//构造含有参数的方法
public Rectangle(double length, double width) {
this.length =
this.width =
public double Aera()
return length *
* Cuboid 子类
package cn.yjlblog.
public class Cuboid extends Rectangle
public double getHeight() {
public void setHeight(double height) {
this.height =
public double getVolume() {
public void setVolume(double volume) {
this.volume =
public Cuboid(double length, double width, double height) {
super(length, width);
this.height =
* TestClass 测试类
package cn.yjlblog.
public class TestClass {
public static void main(String[] args) {
Cuboid rct = new Cuboid(10,20,30);
double v = rct.Aera()*rct.getHeight();
double s = rct.Aera();
System.out.println(&The Rctangle's volume is:&+v);
System.out.println(&The Rctangle's floor space is:&+s);
The Rctangle's volume is:6000.0
The Rctangle's floor space is:200.0
在这个例子中,我觉的并没有实现题目中的效果...enmmmm,以为题目中(2)中说,要求写出计算体积的方法,但是在Cuboid中不会写......于是把体积 的计算方法写在了测试类中....
3、按要求编写一个Java应用程序:
(1)编写一个Shape类,具有属性周长(perimeter)和面积(area);
(2)定义其子类三角形(Triangle)和矩形(Rectangle),分别具有求周长和面积的方法。
(3)定义测试类,在其main方法中创建三角形和矩形类的对象,并赋给Shape类的对象a和b,使用对象a、b来测试其特性。
* Shape 父类
package cn.yjlblog.
public class Shape {
//get set 方法
public double getPerimeter() {
public void setPerimeter(double perimeter) {
this.perimeter =
public double getArea() {
public void setArea(double area) {
this.area =
//构造方法
public Shape(double perimeter, double area) {
this.perimeter =
this.area =
* Triangle 子类
package cn.yjlblog.
public class Triangle extends Shape {
public Triangle(double perimeter, double area) {
super(perimeter, area);
// TODO Auto-generated constructor s
private double a1;
private double a2;
private double a3;
//set get 方法
public double getA1() {
return a1;
public void setA1(double a1) {
this.a1 = a1;
public double getA2() {
return a2;
public void setA2(double a2) {
this.a2 = a2;
public double getA3() {
return a3;
public void setA3(double a3) {
this.a3 = a3;
public double perimeter()
return a1+a2+a3;
public double
double s1=(a1+a2+a3)/2;
double s2 = s1*(s1-a1)*(s1-a2)*(s1-a3);
double result = Math.sqrt(s2);
package cn.yjlblog.
* Rectangle 子类
public class Rectangle extends Shape{
public Rectangle(double perimeter, double area) {
super(perimeter, area);
// TODO Auto-generated constructor stub
private double b1;
private double b2;
public double getB1() {
return b1;
public void setB1(double b1) {
this.b1 = b1;
public double getB2() {
return b2;
public void setB2(double b2) {
this.b2 = b2;
public double perimeter()
return (b1+b2)*2;
public double
return b1*b2;
* TestClass 测试类
package cn.yjlblog.
public class TestClass {
public static void main(String[] args) {
Triangle a = new Triangle(0, 0);
a.setA1(3);
a.setA2(4);
a.setA3(5);
System.out.println(a.perimeter());
System.out.println(a.area());
Rectangle b = new Rectangle(0, 0);
b.setB1(3);
b.setB2(4);
System.out.println(b.perimeter());
System.out.println(b.area());
12.0 //三角形周长
//三角形面积
//长方形周长
//长方形面积
这个题目总感觉自己的父类没有用上...enmmm..可能自己的关于java的语法还是.....再想想。
4、按要求编写一个Java应用程序:
(1)编写一个矩形类Rect,包含:两个protected属性:矩形的长length和矩形的宽width;
两个构造方法:
一个带有两个参数的构造方法,用于将width和length属性初始化;
一个不带参数的构造方法,用于将width和length属性初始化为0;
两个方法:
求矩形面积的方法area();
求矩形周长的方法perimeter();
(2)通过继承Rect类编写一个具有确定位置的矩形类PlainRect,其确定位置用矩形的左上角坐标来标识,包含:两个属性:矩形左上角坐标startX和startY
两个构造方法:
一个带有四个参数的构造方法,用于对startX、startY、width和length属性初始化;
一个不带参数的构造方法,用于将startX、startY、width和length属性初始化为0;
一个方法:
判断某个点是否在矩形内部的方法isInside(double x,double y)。如在矩形内,返回true,否则返回false。
提示:点在矩形内的判断条件:
x&=startX&&x&=(startX+length)&&y&=startY&&y&=(startY+width)
(3)编写测试类
创建一个左上角坐标为(10,10),长为20,宽为10的矩形对象;计算并打印输出矩形的面积和周长;并判断点(25.5,13)是否在矩形内,并打印输出相关信息。
public class 测试 {
public static void main(String[] args) {
PlainRect p=new PlainRect(10,10,10,20);
p.perimeter();
System.out.println(&矩形的面积:&+p.area());
System.out.println(&矩形的周长:&+p.perimeter());
p.isInside(25.5,13);
public class Rect {
public Rect(double length,double width) {
//super();
this.length=
this.width=
public Rect() {
//super();
public double area() {
return length*
public double perimeter() {
return length+
public class PlainRect extends Rect {
protected double startX;
protected double startY;
public PlainRect(double startX,double startY,double width,double length) {
this.startX=startX;
this.startY=startY;
this.width=
this.length=
public PlainRect() {
public boolean isInside(double x,double y) {
if(x&=startX&&x&=(startX+length)&&y&=startY&&y&=(startY+width)){
System.out.println(&点在矩形内部&);
System.out.println(&点不在矩形内部&);
阅读(...) 评论()声明一个基类Shape,在此基础上派生出Rectangle和Circle,二者都有GetArea_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
声明一个基类Shape,在此基础上派生出Rectangle和Circle,二者都有GetArea
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
你可能喜欢编写类Shape的派生类:圆类Circle、三角形类Triangle和矩形类Rectangle_百度知道
编写类Shape的派生类:圆类Circle、三角形类Triangle和矩形类Rectangle
并重定义基类的成员函数使之返回正确的结果(show函数要输出对象的基本信息),然后编写程序测试他们。下面是形状类:class Shape{public:double area(){return 0;}double girth({return 0;}void show(){cout&&&Shape Object:&&&}private:};
我有更好的答案
// 完整代码如下:#include &iostream&#include &cmath&// PI定义const double PI = 3.1415926;// Shapeclass Shape{public:
virtual double area(){
virtual double girth(){
virtual void show(){
cout&&&Shape Object:&&&
}};// Circleclass Circle : public Shape{public:
Circle():m_Radius(0) {}
Circle(double radius):m_Radius(radius) {}
~Circle() {}
double area(){
return m_Radius * m_Radius * PI;
double girth(){
return 2 * PI * m_R
void show(){
cout&&&Circle Object&&&
double m_R};// Triangleclass Triangle : public Shape{public:
Triangle():m_EdgeA(0), m_EdgeB(0), m_EdgeC(0) {}
Triangle(double la, double lb, double lc):m_EdgeA(la), m_EdgeB(lb), m_EdgeC(lc) {}
~Triangle() {}
double area(){
double temp = girth() * 0.5;
return sqrt( temp * (temp-m_EdgeA) * (temp-m_EdgeB) * (temp-m_EdgeC) );
double girth(){
return m_EdgeA + m_EdgeB + m_EdgeC;
void show(){
cout&&&Triangle Object&&&
double m_EdgeA;
double m_EdgeB;
double m_EdgeC;};// Rectangleclass Rectangle : public Shape{public:
Rectangle():m_Length(0), m_Width(0) {}
Rectangle(double length, double width):m_Length(length), m_Width(width) {}
~Rectangle() {}
double area(){
return m_Length * m_W
double girth(){
return 2 * (m_Length + m_Width);
void show(){
cout&&&Rectangle Object&&&
double m_L
double m_W};// Testint main(){
Shape *p1 = new Circle(2);
Shape *p2 = new Triangle(3, 4, 5);
Shape *p3 = new Rectangle(6, 7);
cout&&&Area test:&&&endl
&&&p1 = &&&p1-&area()&&endl
&&&p2 = &&&p2-&area()&&endl
&&&p3 = &&&p3-&area()&&endl&&
cout&&&Girth test:&&&endl
&&&p1 = &&&p1-&girth()&&endl
&&&p2 = &&&p2-&girth()&&endl
&&&p3 = &&&p3-&girth()&&endl&&
cout&&&Type test:&&&
p1-&show();
p2-&show();
p3-&show();
delete p1; p1 = NULL;
delete p2; p2 = NULL;
delete p3; p3 = NULL;
return 0;}// 测试结果:
为您推荐:
其他类似问题
rectangle的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。}

我要回帖

更多关于 msoshaperectangle 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信