1 //1.矩形类的定义及应用
2 package classwork_5;
3
4 public class juxing1 {
5 private double a,b;//长,宽
6 private double x,y;//坐标
7 public juxing1(double a, double b, double x, double y) {
8 this.a = a;
9 this.b = b;
10 this.x = x;
11 this.y = y;
12 }
13
14 public juxing1() {
15 }
16
17 public double getA() {
18 return a;
19 }
20
21 public void setA(double a) {
22 this.a = a;
23 }
24
25 public double getB() {
26 return b;
27 }
28
29 public void setB(double b) {
30 this.b = b;
31 }
32
33 public double getX() {
34 return x;
35 }
36
37 public void setX(double x) {
38 this.x = x;
39 }
40
41 public double getY() {
42 return y;
43 }
44
45 public void setY(double y) {
46 this.y = y;
47 }
48
49 public double S(){//面积
50 return a*b;
51 }
52 public double C(){//周长
53 return 2*(a+b);
54 }
55 public void print(){
56 System.out.println("矩形的坐标为"+"("+x+","+y+")");
57 System.out.println("矩形的长为:"+a+"矩形的宽为:"+b);
58 System.out.println("矩形的面积为:"+S());
59 System.out.println("矩形的面积为:"+C());
60 }
61 public void print1(){
62 System.out.println("矩形的坐标为"+"("+x+","+y+")");
63 }
64 }
65
66 package classwork_5;
67
68 public class juxing1_test {
69
70 public static void main(String[] args) {
71 juxing1 a= new juxing1(10, 20, 0, 0);
72 a.print();
73 System.out.println("长度变为原来的二倍");
74 a.setA(20);
75 a.print();
76 System.out.println("坐标变成(20,20)");
77 a.setX(20);
78 a.setY(20);
79 a.print1();
80 }
81
82 }
83 //整数运算
84 package classwork_5;
85
86 import java.util.Scanner;
87
88 public class zsyunsuan {
89 private int a,b;
90
91 public zsyunsuan() {
92 Scanner in =new Scanner(System.in);
93 int a=in.nextInt();
94 int b=in.nextInt();
95 zsyunsuan(a, b);
96 }
97 public void zsyunsuan(int a, int b) {
98 this.a = a;
99 this.b = b;
100 }
101 public int add(){
102 return a+b;
103 }
104 public int sub(){
105 return a-b;
106 }
107 public int mul(){
108 return a*b;
109 }
110 public double div(){
111 return (a*1.0/b);
112 }
113
114 }
115 package classwork_5;
116
117 public class zsyunsuan_test {
118
119 public static void main(String[] args) {
120 zsyunsuan a=new zsyunsuan();
121 System.out.println("两数相加的结果为:"+a.add());
122 System.out.println("两数相减的结果为:"+a.sub());
123 System.out.println("两数相乘的结果为:"+a.mul());
124 System.out.println("两数相除的结果为:"+a.div());
125 }
126
127 }
128 //实数运算
129 package classwork_5;
130
131 import java.util.Scanner;
132
133 public class ssyunsuan {
134 private double a,b;
135
136 public ssyunsuan() {
137 Scanner in =new Scanner(System.in);
138 double a=in.nextDouble();
139 double b=in.nextDouble();
140 ssyunsuan(a, b);
141 }
142 public void ssyunsuan(double a, double b) {
143 this.a = a;
144 this.b = b;
145 }
146 public double add(){
147 return a+b;
148 }
149 public double sub(){
150 return a-b;
151 }
152 public double mul(){
153 return a*b;
154 }
155 public double div(){
156 return (a*1.0/b);
157 }
158
159 }
160
161 package classwork_5;
162
163 public class ssyunsuan_test {
164
165 public static void main(String[] args) {
166 ssyunsuan a=new ssyunsuan();
167 System.out.println("两数相加的结果为:"+a.add());
168 System.out.println("两数相减的结果为:"+a.sub());
169 System.out.println("两数相乘的结果为:"+a.mul());
170 System.out.println("两数相除的结果为:"+a.div());
171 }
172
173 }
174
175 //复数的运算
176 package test;
177
178 import java.util.Scanner;
179
180 public class complex {//复数类
181 double real;//实部
182 double image;//虚部
183 complex(){
184 Scanner in=new Scanner(System.in);
185 double real=in.nextDouble();
186 double image=in.nextDouble();
187 complex(real,image);
188 }
189 public complex(double real, double image) {//有参构造函数
190 this.real = real;
191 this.image = image;
192 }
193 private void complex(double real, double image) {//给无参构造函数调用
194 this.real = real;
195 this.image = image;
196 }
197 public double getReal() {
198 return real;
199 }
200 public void setReal(double real) {
201 this.real = real;
202 }
203 public double getImage() {
204 return image;
205 }
206 public void setImage(double image) {
207 this.image = image;
208 }
209 //复数相加
210 complex add(complex a) {
211 double real2=a.getReal();
212 double image2=a.getImage();
213 double newreal=real+real2;
214 double newimage=image+image2;
215 complex result=new complex(newreal, newimage);
216 return result;
217 }
218 //复数相减
219 complex sub(complex a) {
220 double real2=a.getReal();
221 double image2=a.getImage();
222 double newreal=real-real2;
223 double newimage=image-image2;
224 complex result=new complex(newreal, newimage);
225 return result;
226 }
227 //复数相乘
228 complex mul(complex a) {
229 double real2=a.getReal();
230 double image2=a.getImage();
231 double newreal=real*real2-image*image2;
232 double newimage=image*real2 + real*image2;
233 complex result=new complex(newreal, newimage);
234 return result;
235 }
236 //复数相除
237 complex div(complex a) {
238 double real2=a.getReal();
239 double image2=a.getImage();
240 double newreal=(real*real2+image*image2)/(real2*real2 + image2*image2);
241 double newimage=(image*real2 - real*image2)/(real2*real2 + image2*image2);
242 complex result=new complex(newreal, newimage);
243 return result;
244 }
245 // 输出
246 public void print(){
247 if(image > 0){
248 System.out.println(real + " + " + image + "i");
249 }else if(image < 0){
250 System.out.println(real + "" + image + "i");
251 }else{
252 System.out.println(real);
253 }
254 }
255 }
256 package test;
257
258 public class complextest {
259
260 public static void main(String[] args) {
261 System.out.println("请输入第一个复数的实部和虚部:");
262 complex a1=new complex();
263
264 System.out.println("请输入第二个复数的实部和虚部:");
265 complex a2=new complex();
266
267 complex add=a1.add(a2);
268 complex sub=a1.sub(a2);
269 complex mul=a1.mul(a2);
270 complex div=a1.div(a2);
271
272 //输出
273 System.out.println("相加的结果为:");
274 add.print();
275 System.out.println("相减结果为:");
276 sub.print();
277 System.out.println("相乘的结果为:");
278 mul.print();
279 System.out.println("相除的结果为:");
280 div.print();
281 }
282
283 }
284 //矩阵的运算
285 package classwork_5;
286
287 import java.util.Scanner;
288
289 public class jzyunsuan {
290 private int r,c;
291 private int[][] a;
292 private int[][] x;
293 private int[][] b;
294
295 public jzyunsuan(int r, int c) {
296 this.r = r;
297 this.c = c;
298 this.a=new int[r][c];
299 this.b=new int[r][c];
300 this.x=new int[r][c];
301 }
302 public jzyunsuan() {
303
304 }
305
306 //初始化矩阵
307 public void init(){
308 for(int i=0;i<a.length;++i){
309 for(int j=0;j<a[i].length;++j){
310 a[i][j]=2;
311 b[i][j]=1;
312 x[i][j]=0;
313 }
314 }
315 }
316
317 public void add(){
318 for(int i=0;i<a.length;++i){
319 for(int j=0;j<a[i].length;++j){
320 x[i][j]=a[i][j]+b[i][j];
321 }
322 }
323 }
324 public void sub(){
325 for(int i=0;i<a.length;++i){
326 for(int j=0;j<a[i].length;++j){
327 x[i][j]=a[i][j]-b[i][j];
328 }
329 }
330 }
331 public void print1(){
332 for(int i=0;i<a.length;++i){
333 for(int j=0;j<a[i].length;++j){
334 System.out.print(a[i][j]+" ");
335 }
336 System.out.println();
337 }
338 }
339 public void print2(){
340 for(int i=0;i<a.length;++i){
341 for(int j=0;j<a[i].length;++j){
342 System.out.print(b[i][j]+" ");
343 }
344 System.out.println();
345 }
346 }
347 public void print(){
348 for(int i=0;i<a.length;++i){
349 for(int j=0;j<a[i].length;++j){
350 System.out.print(x[i][j]+" ");
351 }
352 System.out.println();
353 }
354 }
355 }
356 package classwork_5;
357
358 public class jzyunsuan_test {
359
360 public static void main(String[] args) {
361 jzyunsuan a=new jzyunsuan(3,3);
362 a.init();
363 System.out.println("初始化矩阵a为");
364 a.print1();
365 System.out.println("初始化矩阵b为");
366 a.print2();
367 System.out.println("矩阵相加的结果为:");
368 a.add();
369 a.print();
370 System.out.println("矩阵相减的结果为:");
371 a.sub();
372 a.print();
373
374 }
375
376 }
377 //圆的定义和描述
378 package test;
379
380 public class circle {
381 private double r;
382
383 public circle(double r) {
384 this.r = r;
385 }
386 public double C(){
387 return 2*r*Math.PI;
388 }
389 public double S(){
390 return Math.PI*r*r;
391 }
392 public void output(){
393 System.out.println("圆的的半径为"+r+"\n"+"圆的周长为:"+C()+"\n"+"圆的面积为:"+S());
394 }
395
396 }
397 package test;
398
399 public class testcircle {
400
401 public static void main(String[] args) {
402 circle circle=new circle(4);
403 circle.output();
404
405 }
406
407 }
408 //三角形的定义与描述
409 package test;
410
411 public class sjx {
412 private double a,b,c;
413
414 public sjx(double a, double b, double c) {
415 this.a = a;
416 this.b = b;
417 this.c = c;
418 }
419
420 public double C(){
421 return a+b+c;
422 }
423 public double S(){
424 double p=C()*0.5;
425 double s=Math.sqrt(p*(p-a)*(p-b)*(p-c));
426 return s;
427 }
428 public void print(){
429 System.out.println(a+" "+b+" "+c+" ");
430 }
431 }
432 package test;
433
434 public class testsjx {
435
436 public static void main(String[] args) {
437 sjx sjx=new sjx(3,4,5);
438 System.out.println("三角形的三边分别为");
439 sjx.print();
440 System.out.println("三角形的周长为:"+sjx.C());
441 System.out.println("三角形的面积为:"+sjx.S());
442 }
443
444 }
445 //圆柱的定义和描述
446 package test;
447
448 public class yz {
449 private double r,h;
450
451 public yz(double r, double h) {
452 this.r = r;
453 this.h = h;
454 }
455 public double DC(){
456 return 2*r*Math.PI;
457 }
458 public double DS(){
459 return Math.PI*r*r;
460 }
461 public double BS(){//圆柱的表面积
462 return 2*DS()+DC()*h;
463 }
464 public double V(){//圆柱的体积
465 return DS()*h;
466 }
467 public void output(){
468 System.out.println("圆柱的的半径为"+r+"\n"+"圆柱的高为"+h+"\n"+"圆柱的表面积为:"+BS()+"\n"+"圆柱的体积为:"+V());
469 }
470 }
471 package test;
472
473 public class testyz {
474
475 public static void main(String[] args) {
476 yz yz=new yz(3,4);
477
478 yz.output();
479 }
480
481 }
482 //定义一个正立方体求其表面积和体积
483 package classwork_5;
484
485 public class lft {
486 private double a,b,h;
487
488 public lft(double a, double b, double h) {
489 this.a = a;
490 this.b = b;
491 this.h = h;
492 }
493 public double V(){
494 return a*b*h;
495 }
496 public double S(){
497 return a*b*6;
498 }
499 public void print(){
500 System.out.println("正立方体的表面积为:"+S()+"正方体的体积为:"+V());
501 }
502 }
503 package classwork_5;
504
505 public class lft_test {
506
507 public static void main(String[] args) {
508 lft a=new lft(1, 2, 3);
509 a.print();
510 }
511
512 }
513

java实验类的实现的更多相关文章

  1. Java实验1 - 类的继承(super)- 创建checkaccount继承account

    笔记总结: /** 任务81: 继承性,(降低代码亢余度) * 1.class 子类A Extends 父类B,(private 的内容无法被继承) * 2. 方法可以覆盖(Overrides), 注 ...

  2. Java实验四

    20145113 Java实验四 快捷键 之前没怎么记ISDEA的快捷键,但是熟练使用快捷键可以带来很多的便利,于是先开始学习一些常用的快捷键,就采用它默认的快捷键,这样后期就不会出现冲突,一些and ...

  3. java实验三20135104

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计                         班级:1351            姓名:刘帅      ...

  4. Java实验二20135104

    课程:Java程序设计          班级: 1351 姓名:刘帅                学号:20135104 成绩:             指导教师:娄嘉鹏       实验日期:2 ...

  5. Java实验报告二:Java面向对象程序设计

    Java实验报告二:Java面向对象程序设计                                                                               ...

  6. java实验一实验报告

    Java实验报告一:Java开发环境的熟悉                                                                               ...

  7. 20175212童皓桢 Java实验二-面向对象程序设计实验报告

    20175212童皓桢 Java实验二-面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设 ...

  8. Java实验报告(实验二)

    课程:Java程序设计          班级: 1351 姓名:王玮怡                学号:20135116 成绩:             指导教师:娄嘉鹏       实验日期: ...

  9. 20145106 java实验二

    1)复数类ComplexNumber的属性 m_dRealPart: 实部,代表复数的实数部分 m_dImaginPart: 虚部,代表复数的虚数部分 public class ComplexNumb ...

随机推荐

  1. abp(net core)+easyui+efcore实现仓储管理系统——出库管理之四(五十三)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...

  2. elk部署(实战一)

    项目介绍: 系统:redhat7.6 软件:es+logstash+kibana  6.1 IP+主机名 192.168.0.10    elk1 192.168.0.10    elk2 192.1 ...

  3. [Luogu P1122]最大子树和 (简单树形DP)

    题面 传送门:https://www.luogu.org/problemnew/show/P1122 Solution 这是一道简单的树形DP题. 首先,我们可以转换一下题面,可以发现,题目要求我们求 ...

  4. node.js+express框架 修改后自启【不需要再执行start】

    我们每次修改完后都需要重新启动下才能刷新,就很麻烦'nodemon'解决了这个问题. 这里直接进行全局安装 npm install -g nodemon 安装到本地 npm install nodem ...

  5. CF1137A/1138C Skyscrapers

    排序+数据结构 将每一行(每一列)都排个序,并将原位置的在这一行(列)中的排行记录在一个数组里 注意,要将楼高度相同的元素看作一个元素 如 1 1 4 5 6 8 8,则排行是      1 1 2 ...

  6. TRUNCATE 有约束的表

    在有外键约束的情况下,truncate 表时,会报错, 我们可以设置外键检测为flase,执行完truncate命令后,再启用 SET foreign_key_checks = 0;TRUNCATE ...

  7. Oracle数据库操作相关

    1. 导出dmp 文件 (1)导出数据库所有的用户数据: exp system/manage@ORCL file=D:\oracle_dmp\data1.dmp full=y (2)导出指定的用户数据 ...

  8. CORS跨域请求:前后端分离

    1. 请求过滤器: /** * OncePerRequestFilter保证在任何Servlet容器中都是一个请求只执行一次的过滤器. */ public class CorsFilter exten ...

  9. TCP数据接收及快速路径和慢速路径

    概述 tcp握手完成后,收到数据包后,调用路径为tcp_v4_rcv->tcp_v4_do_rcv->tcp_rcv_established在tcp_rcv_established中处理T ...

  10. 爬虫练习之正则表达式爬取猫眼电影Top100

    #猫眼电影Top100import requests,re,timedef get_one_page(url): headers={ 'User-Agent':'Mozilla/5.0 (Window ...