java实验作业类的定义与描述

  1 //1三角形的定义与描述
  2 package test;
  3 
  4 public class sjx {
  5      private double a,b,c;
  6 
  7   public sjx(double a, double b, double c) {
  8     this.a = a;
  9     this.b = b;
 10     this.c = c;
 11   }
 12      
 13   public double C(){
 14     return a+b+c;
 15   }
 16   public double S(){
 17     double p=C()*0.5;
 18     double s=Math.sqrt(p*(p-a)*(p-b)*(p-c));
 19     return s;
 20   }
 21   public void print(){
 22     System.out.println(a+" "+b+" "+c+" ");
 23   }
 24 }
 25 package test;
 26 
 27 public class testsjx {
 28 
 29   public static void main(String[] args) {
 30     sjx sjx=new sjx(3,4,5);
 31     System.out.println("三角形的三边分别为");
 32     sjx.print();
 33     System.out.println("三角形的周长为:"+sjx.C());
 34     System.out.println("三角形的面积为:"+sjx.S());    
 35   }
 36 
 37 }
 38 //2.圆的定义和描述
 39 package test;
 40 
 41 public class circle {
 42        private double r;
 43 
 44   public circle(double r) {
 45     this.r = r;
 46   }
 47   public double C(){
 48     return 2*r*Math.PI;
 49   }
 50   public double S(){
 51     return Math.PI*r*r;
 52   }
 53   public void output(){
 54     System.out.println("圆的的半径为"+r+"\n"+"圆的周长为:"+C()+"\n"+"圆的面积为:"+S());
 55   }
 56        
 57 }
 58 package test;
 59 
 60 public class testcircle {
 61 
 62   public static void main(String[] args) {
 63   circle circle=new circle(4);
 64   circle.output();
 65 
 66   }
 67 
 68 }
 69 //3.圆柱的定义和描述
 70 package test;
 71 
 72 public class yz {
 73     private double r,h;
 74 
 75   public yz(double r, double h) {
 76     this.r = r;
 77     this.h = h;
 78   }
 79   public double DC(){
 80     return 2*r*Math.PI;
 81   }
 82   public double DS(){
 83     return Math.PI*r*r;
 84   }
 85   public double BS(){//圆柱的表面积
 86     return 2*DS()+DC()*h;
 87   }
 88   public double V(){//圆柱的体积
 89     return DS()*h;
 90   }
 91   public void output(){
 92     System.out.println("圆柱的的半径为"+r+"\n"+"圆柱的高为"+h+"\n"+"圆柱的表面积为:"+BS()+"\n"+"圆柱的体积为:"+V());
 93   }
 94 }
 95 package test;
 96 
 97 public class testyz {
 98 
 99   public static void main(String[] args) {
100     yz yz=new yz(3,4);
101     
102        yz.output();
103   }
104 
105 }
106 //5.图形的定义与描述
107 package test;
108 
109 public class tx {
110       private String xz;//图形的形状
111       private double dx;//图形的大小
112       private String zx;//图形的存在形式,立体or平面
113   public tx(String xz, double dx, String zx) {
114     this.xz = xz;
115     this.dx = dx;
116     this.zx = zx;
117   }
118   public void output(){
119     System.out.println("图形的形状:"+xz+"\n"+"图形的大小:"+dx+"\n"+"图形的存在形式:"+zx);
120   }  
121 }
122 package test;
123 
124 public class testtx {
125 
126   public static void main(String[] args) {
127        
128     tx tx=new tx("圆形",40,"平面");
129     tx.output();
130   }
131 
132 }
133 //6计算机的定义与描述
134 package test;
135 
136 public class computer {
137      private String cpu;
138      private String xk;
139      private String zb;
140   public computer(String cpu, String xk, String zb) {
141     this.cpu = cpu;
142     this.xk = xk;
143     this.zb = zb;
144   }
145   public void output(){
146     System.out.println("cpu为:"+cpu+"\n"+"显卡为:"+xk+"\n"+"主板为:"+zb);
147   }  
148 }
149 package test;
150 
151 import java.util.Scanner;
152 
153 public class testcomputer {
154 
155   public static void main(String[] args) {
156      String a,b,c;
157      Scanner in=new Scanner(System.in);
158      System.out.println("请输入计算机的cpu/显卡/和主板类型:");
159      a=in.next();
160      b=in.next();
161      c=in.next();
162      computer computer=new computer(a, b, c);
163      computer.output();
164   }
165 
166 }
167 //7.课程的定义和描述
168 package test;
169 
170 public class kc {
171    private String lesson;//什么课
172    private String time;//什么时候上课
173    private String teacher;//什么老师教授
174   public kc(String lesson, String time, String teacher) {
175   this.lesson = lesson;
176   this.time = time;
177   this.teacher = teacher;
178 }
179   public void output(){
180     System.out.println("课程为:"+lesson+"\n"+"老师为:"+teacher+"\n"+"上课时间为:"+time);
181   }
182 }
183 package test;
184 
185 public class testkc {
186 
187   public static void main(String[] args) {
188     kc kc=new kc("java程序设计", "周一下午第二节和周五上午第二节", "张老师");
189            kc.output();
190   }
191 
192 }
193 //8日期的定义与描述
194 package test;
195 
196 public class date {
197      private String today;//今天几号
198      private String luck;//是否为吉日
199   public date(String today, String luck) {
200     this.today = today;
201     this.luck = luck;
202   }
203   public void output(){
204     System.out.println("今天几号:"+today+"\n"+"是否为吉日:"+luck);
205   }
206 }
207 package test;
208 
209 public class testdate {
210 
211   public static void main(String[] args) {
212       date date=new date("2020/11/06", "是");
213       date.output();
214   }
215 
216 }
217 //9文件夹的定义与描述
218 package test;
219 
220 public class file {
221      private String pan;//哪个盘上的文件夹
222      private String kj;//是否为可见文件夹
223   public file(String pan, String kj) {
224     this.pan = pan;
225     this.kj = kj;
226   }
227   public void output(){
228     System.out.println("哪个盘上的文件夹:"+pan+"\n"+"是否为可见文件夹:"+kj);
229   }     
230 }
231 package test;
232 
233 public class testfile {
234 
235   public static void main(String[] args) {
236       file file =new file("D盘", "是");
237       file.output();
238   }
239 
240 }
241 //10.上课的课堂的描述
242 package test;
243 
244 public class kt {
245   private String teacher;// 上课老师为
246   private String qiandao;// 是否签到
247   private String homework;// 是否留家庭作业了
248 
249   public kt(String teacher, String qiandao, String homework) {
250     this.teacher = teacher;
251     this.qiandao = qiandao;
252     this.homework = homework;
253   }
254   public void output(){
255     System.out.println("上课老师为:"+teacher+"\n"+"是否签到:"+qiandao+"\n"+"是否留家庭作业了:"+homework);
256   }
257 }
258 package test;
259 
260 public class testkt {
261 
262   public static void main(String[] args) {
263      kt kt=new kt("张老师", "是", "没有");
264      kt.output();
265   }
266 
267 }
268 //11.手机的定义与描述
269 package test;
270 
271 public class phone {
272       private String user;//使用者
273       private int G;//几G手机
274       private int rom;//存储空间多大
275       private int ram;//运行内存多大
276   public phone(String user, int g, int rom, int ram) {
277     this.user = user;
278     G = g;
279     this.rom = rom;
280     this.ram = ram;
281   }
282   public void output(){
283     System.out.println("手机使用者为:"+user+"\n"+G+"G手机"+"\n"+"存储空间为:"+rom+"\n"+"运行内存为:"+ram);
284   }  
285 }
286 package test;
287 
288 public class phonetest {
289 
290   public static void main(String[] args) {
291   phone phone=new phone("小明", 5, 512, 16);
292   phone.output();
293   }
294 
295 }
296 //12.教材如何定义与描述的
297 package test;
298 
299 public class textbook {
300        private String name;//书名
301        private String author;//作者
302        private String kind;//什么类别的
303   public textbook(String name, String author, String kind) {
304     this.name = name;
305     this.author = author;
306     this.kind = kind;
307   }
308   public void output(){
309     System.out.println("书名为"+name+"\n"+"作者为:"+author+"\n"+"书的类别为:"+kind);
310   }
311 }
312 package test;
313 
314 public class textbooktest {
315 
316   public static void main(String[] args) {
317     textbook textbook=new textbook("java", "小明", "教育用书");
318     textbook.output();
319   }
320 
321 }
322 //13.班级的定义与描述
323 package test;
324 
325 public class class_ {
326      private String name;//班级名字
327      private int person;//班级人数
328      private String banzhang;//班长
329   public class_(String name, int person, String banzhang) {
330     this.name = name;
331     this.person = person;
332     this.banzhang = banzhang;
333   }
334   public void output(){
335     System.out.println("班级名字为"+name+"\n"+"班长为:"+banzhang+"\n"+"班级人数为:"+person);
336   }
337 }
338 package test;
339 
340 public class class_test {
341 
342   public static void main(String[] args) {
343     class_ a=new class_("计算机六班", 25, "小明");
344     a.output();
345   }
346 
347 }
348 //14.选课的定义与描述
349 package test;
350 
351 public class xk {
352      private String time;//选课时间
353      private String bs;//系统内置的必修课
354      private String xx;//选修课
355   public xk(String time, String bs, String xx) {
356     this.time = time;
357     this.bs = bs;
358     this.xx = xx;
359   }
360   public void output(){
361     System.out.println("选课时间为"+time+"\n"+"必修课为:"+bs+"\n"+"选修课为:"+xx);
362   }
363 }
364 package test;
365 
366 public class xktest {
367 
368   public static void main(String[] args) {
369     xk a=new xk("2021年一月13日", "javaweb", "美学");
370     a.output();
371 
372   }
373 
374 }
375 //15.一个大学如何定义与描述
376 package test;
377 
378 public class university {
379       private String local;//位于哪里
380       private String name;//大学名字
381       private int ss;//在校学生
382   public university(String local, String name, int ss) {
383     this.local = local;
384     this.name = name;
385     this.ss = ss;
386   }
387   public void output(){
388     System.out.println("大学校名为"+name+"\n"+"位于:"+local+"\n"+"在校学生人数为:"+ss);
389   }
390 }
391 package test;
392 
393 public class universitytest {
394 
395   public static void main(String[] args) {
396     university a=new university("泰安市", "山东农业大学", 40000);
397     a.output();
398 
399   }
400 
401 }
402 //1.直线方程一般式
403 package test;
404 
405 import java.util.Scanner;
406 
407 public class line_1 {
408       private double a;
409       private double b;
410       private double c;
411       private double x;
412       private double y;
413       public line_1(){
414       }
415   public line_1(double a, double b, double c) {
416     this.a = a;
417     this.b = b;
418     this.c = c;
419   }
420   public double getX() {
421     return x;
422   }
423   public void setX(double x) {
424     this.x = x;
425   }
426   public double getY() {
427     return y;
428   }
429   public void setY(double y) {
430     this.y = y;
431   }
432   public double d() {
433     double fm=Math.sqrt(a*a+b*b);
434     double fz=Math.abs(a*x+b*y+c);
435     return fz/fm;
436   }
437   public void jd() {
438     double xz=-c/a;//直线与x轴上的交点
439     double yz=-c/b;//直线与y轴上的交点
440     System.out.println("直线与x轴上的交点为:"+xz);
441     System.out.println("直线与y轴上的交点为:"+yz);
442   }
443   public void input() {
444     System.out.println("请输入一般式直线方程的A,B,C三个参数:");
445     Scanner in=new Scanner(System.in);
446      a=in.nextDouble();
447      b=in.nextDouble();
448      c=in.nextDouble();
449     System.out.println("宁所输入的直线方程为:"+a+"*X+"+b+"*Y+"+c+"*C"+"=0");
450     System.out.println("请输入坐标x,y以求其到直线的距离");
451     x=in.nextDouble();
452     y=in.nextDouble();
453   }
454   public void output() {
455     System.out.println("点"+"("+x+","+y+")"+"到"+a+"*X+"+b+"*Y+"+c+"*C"+"=0"+"的距离为:"+d());
456   }
457      
458 }
459 package test;
460 
461 public class line_1test {
462 
463   public static void main(String[] args) {
464     line_1 a=new line_1();
465     a.input();
466         a.output();
467         a.jd();
468   }
469 
470 }
471 //2.直线方程点斜式
472 package test;
473 
474 public class line_2 {
475   private double x0, x1;
476   private double y0, y1;
477   private double k;
478 
479   public line_2(double x0, double y0, double x1, double y1, double k) {
480     this.x0 = x0;
481     this.y0 = y0;
482     this.x1 = x1;
483     this.y1 = y1;
484     this.k = k;
485   }
486 
487   public double d() {
488     double fm = Math.sqrt(1 + k * k);
489     double fz = Math.abs(k * x1 - y1 + y0 - k * x0);
490     return fz / fm;
491   }
492   public void output() {
493     System.out.println("点"+"("+x1+","+y1+")"+"到直线y-2=2*(x-1)"+"的距离为:"+d());
494   }
495 }
496 package test;
497 
498 public class line_2test {
499 
500   public static void main(String[] args) {
501     line_2 a=new line_2(1, 2, 3, 4, 2);
502     a.output();
503   }
504 
505 }
506 //3.直线方程截距式
507 package test;
508 
509 public class line_3 {
510        private double a,b,x,y;
511 
512   public line_3(double a, double b, double x, double y) {
513     this.a = a;
514     this.b = b;
515     this.x = x;
516     this.y = y;
517   }
518       private double d() {
519       double fm = Math.sqrt(a*a+b*b);
520       double fz = Math.abs(b*x+a*y-a*b);
521       return fz / fm;
522       }
523       public void output() {
524         System.out.println("点"+"("+x+","+y+")"+"到直线x/1+y/2=1"+"的距离为:"+d());
525       }
526 }
527 package test;
528 
529 public class line_3test {
530 
531   public static void main(String[] args) {
532     line_3 a=new line_3(1, 2, 3, 4);
533     a.output();
534   }
535 
536 }
537 //4.直线方程斜截式
538 package test;
539 
540 public class line_4 {
541   private double k, b, x, y;
542 
543   public line_4(double k, double b, double x, double y) {
544     this.k = k;
545     this.b = b;
546     this.x = x;
547     this.y = y;
548   }
549 
550   private double d() {
551     double fm = Math.sqrt(1 + k * k);
552     double fz = Math.abs(k * x - y + b);
553     return fz / fm;
554   }
555 
556   public void output() {
557     System.out.println("点" + "(" + x + "," + y + ")" + "到直线y=1*x+b" + "的距离为:" + d());
558   }
559 }
560 package test;
561 
562 public class line_4test {
563 
564   public static void main(String[] args) {
565     line_4 a=new line_4(1, 2, 3, 4);
566     a.output();
567   }
568 
569 }
570 //5.直线方程两点式
571 package test;
572 
573 public class line_5 {
574         private double x,y,x1,y1,x2,y2;
575     public line_5(double x, double y, double x1, double y1, double x2, double y2) {
576       this.x = x;
577       this.y = y;
578       this.x1 = x1;
579       this.y1 = y1;
580       this.x2 = x2;
581       this.y2 = y2;
582     }
583     private double d() {
584       double k=(y2-y1)/(x2-x1);
585       double fm = Math.sqrt(1 + k * k);
586       double fz = Math.abs(k * x - y + y1 - k * x1);
587       return fz / fm;
588     }
589     public void output() {
590       System.out.println("点" + "(" + x + "," + y + ")" + "到直线(y-4)/(6-4)=(x-3)/(5-3)" + "的距离为:" + d());
591     }
592 }
593 package test;
594 
595 public class line_5test {
596 
597   public static void main(String[] args) {
598     line_5 a=new line_5(6, 5, 3, 4, 5, 6);
599     a.output();
600   }
601 
602 }
603 //定义素数
604 package test;
605 
606 public class sushu {
607        private int i,j,l,r;
608        public sushu() {
609          
610        }
611        
612     public int getL() {
613     return l;
614   }
615 
616   public void setL(int l) {
617     this.l = l;
618   }
619 
620   public int getR() {
621     return r;
622   }
623 
624   public void setR(int r) {
625     this.r = r;
626   }
627     
628   public sushu(int l, int r) {
629     this.l = l;
630     this.r = r;
631   }
632 
633   public void fun() {
634     int count=0;
635     int m=l;
636     if(l==1) {
637       l=2;
638     }
639      System.out.println(m+"到"+r+"之间的素数为:");
640          for(i=l;i<=r;++i) {
641            int t=0;
642            for(j=2;j<=Math.sqrt(i);++j) {
643              if(i%j==0) {
644                ++t;
645              }
646            }
647            if(t==0) {
648             
649              System.out.print(i+" ");
650              count++;
651              if(count%5==0) {
652                System.out.println();
653              }
654            }
655          }
656        }
657   
658   
659 }
660 package test;
661 
662 import java.util.Scanner;
663 
664 public class sushutest {
665 
666   public static void main(String[] args) {
667   System.out.println("请输入宁想取那段区间的素数:");
668   Scanner in=new Scanner(System.in);
669   int l=in.nextInt();
670   int r=in.nextInt();
671   sushu a=new sushu(l, r);
672   a.fun();
673   }
674 
675 }

 

posted @ 2020-11-21 19:22  丁帅帅dss  阅读(211)  评论(0)    收藏  举报