设计一个表示二维平面上点的类Point,包含有表示坐标位置的Protect类型的成员变量

获取和设置x和y值的public方法

package classwork_6;

public class Point {
protected double x, y; public Point(double x, double y) {
this.x = x;
this.y = y;
} public Point() { } public double getX() {
return x;
} public void setX(double x) {
this.x = x;
} public double getY() {
return y;
} public void setY(double y) {
this.y = y;
} }

设计一个表示二维平面上的圆的类Circle,它继承父类Point,还包含有表示圆的半径的

protected类型的成员变量r,获取和设置r值的public方法和计算圆面积的public方法

 1 package classwork_6;
2
3 public class Circle extends Point {
4 protected double r;
5
6 public Circle(double x, double y, double r) {
7 super(x, y);
8 this.r = r;
9 }
10
11 public Circle() {
12 super();
13 }
14
15 public double getR() {
16 return r;
17 }
18
19 public void setR(double r) {
20 this.r = r;
21 }
22
23 public double S() {
24 return Math.PI * r * r;
25 }
26
27 }
28 package classwork_6;
29
30 public class Cylinder extends Circle {
31 protected double h;
32
33 public Cylinder(double x, double y, double r, double h) {
34 super(x, y, r);
35 this.h = h;
36 }
37
38 public double V() {
39 Circle a = new Circle(x, y, r);
40 return a.S() * h;
41 }
42
43 @Override
44 public String toString() {
45 return "Cylinder [h=" + h + ", r=" + r + ", x=" + x + ", y=" + y + ", V()=" + V() + "]";
46 }
47
48 }
49 package classwork_6;
50
51 public class Test_pcc {
52
53 public static void main(String[] args) {
54 Cylinder a = new Cylinder(0, 0, 1, 2);
55 System.out.println(a.toString());
56 }
57
58 }

定义一个矩形类,该矩形具有左上角的坐标(x,y),长度,宽度属性

并具有计算面积,周长,显示矩形信息的方法

 1 package classwork_6;
2
3 public class Jx {
4 protected double x;
5 protected double y;
6 protected double l;
7 protected double w;
8
9 public Jx(double x, double y, double l, double w) {
10 this.x = x;
11 this.y = y;
12 this.l = l;
13 this.w = w;
14 }
15
16 public Jx() {
17 }
18
19
20 public double getL() {
21 return l;
22 }
23
24 public void setL(double l) {
25 this.l = l;
26 }
27
28 public double getW() {
29 return w;
30 }
31
32 public void setW(double w) {
33 this.w = w;
34 }
35
36 public double S() {
37 return l*w;
38 }
39 public double C() {
40 return (l+w)*2;
41 }
42
43 @Override
44 public String toString() {
45 return "Jx [x=" + x + ", y=" + y + ", l=" + l + ", w=" + w + ", S()=" + S() + ", C()=" + C() + "]";
46 }
47
48
49 }
50 package classwork_6;
51
52 public class Jxlft extends Jx {
53 private double h;
54
55 public Jxlft(double x, double y, double l, double w, double h) {
56 super(x, y, l, w);
57 this.h = h;
58 }
59
60 public Jxlft() {
61 super();
62 }
63
64 public Jxlft(double x, double y, double l, double w) {
65 super(x, y, l, w);
66 }
67 public double V() {
68 Jx a =new Jx(x, y, l, w);
69 return a.S()*h;
70 }
71 public double BS() {
72 Jx a =new Jx();
73 return (a.S()+l*h+w*h)*2;
74 }
75
76 @Override
77 public String toString() {
78 return "Jxlft [h=" + h + ", x=" + x + ", y=" + y + ", l=" + l + ", w=" + w + ", V()=" + V() + ", BS()=" + BS()
79 + "]";
80 }
81
82 }
83 package classwork_6;
84
85 public class Test_jx {
86
87 public static void main(String[] args) {
88 Jxlft a=new Jxlft(0, 0, 1, 2, 2);
89 System.out.println(a.toString());
90 }
91
92 }

最新文章

  1. HP新学知识
  2. ckeditor简单的演示
  3. js的闭包
  4. 使用my exclipse对数据库进行操作(2)
  5. 开机取消显示 系统准备工具(Sysprep)
  6. (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)
  7. store procedure example
  8. HDU2059(龟兔赛跑)
  9. Android 打造自己的个性化应用(三):应用程序的插件化
  10. ibatis复用SQL片段、引入片段 动态条件增加
  11. 在Win7的IIS上搭建FTP服务及用户授权——转载!!
  12. Codeforces 489C Given Length and Sum of Digits...
  13. c vs c++ in strcut and class
  14. u-boot添加一个hello命令
  15. Unknown column 'user_uid' in 'field list' sql错误解决过程
  16. springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
  17. Evosuite使用方法入门
  18. 基于webpack的react脚手架
  19. 树莓派上的软件安装和卸载命令汇总 [ZT]
  20. CMS3.0——初次邂逅express

热门文章

  1. MVC框架的代码审计小教程
  2. PHP中双引号和单引号的区别
  3. .NET内存分析工具-dotMemory
  4. 正式班D21
  5. eyou升级弹窗、云插件库、接口配置、功能开关【按需显示插件】
  6. Charles使用part3——安装证书&手机抓取https请求
  7. Python 3.9就要来了......,令人兴奋的时刻
  8. Pycharm激活码无偿分享,2020年最新Pycharm永久激活码!
  9. 微信三方平台开发上传base64格式图片至临时素材
  10. 2. RDD(弹性分布式数据集Resilient Distributed dataset)