- 2
- 0
- 约2.16千字
- 约 4页
- 2024-07-13 发布于上海
- 举报
//实验四第一题源程序classPoint2D
{
intx;inty;
Point2D(intx,inty)
{
this.x=x;this.y=y;
}
voidoffset(inta,intb)
{
x=x+a;y=y+b;
System.out.println(平移后:+x+,+y);
}
voidprint(Point2Dp2d1,Point2Dp2d2)
{
doubleL1=Math.sqrt(Math.pow((p2d1.x-p2d2.x),2)+Math.pow((p2d1.y-p2d2.y),2));System.out.println(L1=+L1);
}
}
classPoint3DextendsPoint2D
{
intz;
Point3D(intx,inty,intz)
{
super(x,y);this.z=z;
}
Point3D(Point2Dp,intz)
{
super(p.x,p.y);this.z=z;
}
voidoffset(inta,intb,intc)
{
x=x+a;y=y+b;z=z+c;
}
voidprint(Point3Dp3d1,Point3Dp3d2)
{
double
L2=Math.sqrt(Math.pow((p3d1.x-p3d2.x),2)+Math.pow((p3d1.y-p3d2.y),2)+Math.pow((p3d1.z-p3d2.z),2));
System.out.println(L2=+L2);
}
publicstaticvoidmain(String[]args)
{
Point2Dp2d1=newPoint2D(2,3);Point2Dp2d2=newPoint2D(4,5);Point3Dp3d1=newPoint3D(2,3,4);Point3Dp3d2=newPoint3D(4,5,6);p2d1.print(p2d1,p2d2);p3d1.print(p3d1,p3d2);
}
}
//实验四第二题源程序abstractclassShape
{
abstractpublicvoidshowArea();
}
interfaceDiagArea
{
doublegetDiagonal();doublegetArea();
}
classRectangleimplementsDiagArea
{
intw,h;
Rectangle(inti,intj)
{
w=i;h=j;
}
publicvoidshowArea()
{
ints1=w*h;
System.out.println(s矩形=+s1);
}
publicdoublegetDiagonal()
{
doubleL=Math.sqrt(w*w+h*h);System.out.println(对角线长=+L);returnL;
}
publicdoublegetArea()
{
doubles=w*h;
System.out.println(S矩形面积=+s);returns;
}
}
classSquareextendsRectangle
{intx;
Square(intx)
{
super(x,x);//此处修改前为x=i;this.x=x;
}
publicvoidshowArea()
{
ints2=x*x;
System.out.println(s正方形=+s2);
}
}
classCircle
{
intr;
Circle(inti)
{
r=i;
}
publicvoidshowArea()
{
doubles3=Math.PI*(r*r);System.out.println(s圆=+s3);
}
voidshow()
{
System.out.println(圆的半径=+r);
}
}
classAreas
{
publicstaticvoidmain(String[]args)
{
RectangleRe=newRectangle(2,3);SquareSq=newSquare(4);
CircleCi=newCircle(5);Re.showArea();
System.out.println(实现接口运算);
doubleL=Re.getDiagonal();doubleS=Re.getArea();System.out.println(\n);Sq.showArea();
System
您可能关注的文档
- 实习基地申请报告.docx
- 实习计划书分析和总结.docx
- 实习鉴定表分析和总结.docx
- 实习鉴定表及填写信息格式.docx
- 实习期工作总结.docx
- 实习人员登记表.docx
- 实习心得分析和总结.docx
- 实习心得体会1000字.docx
- 实习信分析和总结.docx
- 实习一 Landsat影像数据下载、导入、目视解译与分析资料.docx
- 全过程工程管理造价咨询工程监理项目服务方案投标方案(技术部分).doc
- 招标代理服务投标技术服务方案(技术方案).doc
- AI大模型与AIGC技术在公安领域的应用解决方案(99页 PPT).pptx
- 工业4.0智能制造数字工厂规划方案.pptx
- 树立社会主义核心价值观.docx
- 三年(2023-2025)中考历史真题分类汇编(全国)专题21 科技文化与社会生活(解析版).docx
- 2025年中考道德与法治真题完全解读(吉林卷).pdf
- 2025年中考道德与法治真题完全解读(安徽卷).pdf
- 三年(2023-2025)中考历史真题分类汇编(全国)专题14 人民解放战争(解析版).pdf
- 三年(2023-2025)广东中考历史真题分类汇编:专题03 中国近代史(八年级上册)(解析版).docx
最近下载
- 500t吊车性能表(中文版).pdf VIP
- 人教版八年级上历史知识点总结 .doc VIP
- 米莉的帽子变变变精品解析.ppt VIP
- 职业教育人工智能应用发展报告(2024-2025).pptx VIP
- 2025年高等教育医学类自考-03037药用植物学考试近5年真题集锦(频考类试题)带答案.docx VIP
- TCAQ10201-2024质量管理小组活动准则_可搜索.pdf VIP
- 确定肿瘤的重要基因信息——提取基因图谱信息方法的研究.pdf VIP
- 事业单位嫖娼违法写检讨书.docx VIP
- 人教版物理8年级下册全册教学课件.pptx
- 第二十五章+图形的相似(复习课件)数学冀教版九年级上册.pptx VIP
原创力文档

文档评论(0)