JAVA第十一次作业

 

package www;

public class test1 {
     public static class Point {
     
      int x;
      int y;
     
      public Point(int x0, int y0) {
       super();
       this.x = x0;
       this.y = y0;
      }
     
      public Point() {
       super();
      }
     
      public String movePoint(int dx, int dy) {
       x = dx + x;
       y = dy + y;
       return ("x为" + x + ",y为" + y);
      }
     
      public static void main(String[] args) {
       Point p1 = new Point(1, 2);
       System.out.println(p1.movePoint(4, 3));
       Point p2 = new Point(2, 3);
       System.out.println(p2.movePoint(4, 5));
     
      }
     }
    }

 

 

package www;

public class Rectangle {
            int length;
            int width;
         
            public int getArea(int length, int width) {
                return length * width;
            }
         
            public int getPer(int length, int width) {
                return (length + width) * 2;
            }
         
            public void showAll() {
                System.out.println("长方形的长为"+length+",宽为" +width+ ",周长为"+ (length + width) * 2 + ",面积为" + length * width);
            }
         
            public Rectangle(int length, int width) {
                super();
                this.length = length;
                this.width = width;
         
            }
         
            public static void main(String[] args) {
                Rectangle r = new Rectangle(1, 2);
                r.showAll();
         
            }
         
        }

 

 

package www;

public class Computer {
        char coulour;
        int cpu;
        
        public void show(){
            System.out.println("笔记本颜色是"+coulour+"色"+",型号是"+cpu);
        }
        
        public Computer(char coulour,int cpu){
            super();
            this.coulour=coulour;
            this.cpu=cpu;
        }
          public Computer(){
              super();
          }
    }
    package www;

public class com {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Computer c = new Computer();
           c.coulour = '黑';
           c.cpu = 123;
           c.show();
           Computer c1 = new Computer('白', 456);
           c1.show();
         
          }
         
    }

 

 

 

posted @ 2021-05-22 21:00  好多鱼好多鱼好剩余  阅读(78)  评论(0编辑  收藏  举报