第十二周上机练习+作业

 

 

 

public class Point {
        int X;
        int Y;
        public Point(){}
        public Point(int x,int y){
        X=x;
        Y=y;
    }
        public void movePoint(int dX,int dY){
            X+=dX;
            Y+=dY;
        }
        public void printPoint(){
            System.out.print("X坐标:"+X);
            System.out.print(" ");
            System.out.println("Y坐标:"+Y);
        }
}
public class DaiMa {

    /**
     * @param args
     */
    public static void main(String[] args) {    
    Point p1=new Point() ;
    p1.X=0;
    p1.Y=0;
    p1.printPoint();
    Point p2=new Point(2,3);
    p2.printPoint();
    System.out.println("移动函数调用后");
    p1.movePoint(2, 2);
    p2.movePoint(2, 2);
    p1.printPoint();
    p2.printPoint();
    }
}    

public class Rectangle {
    public Rectangle(){
        
    }
    private int m_Length;
    private int m_Width;
    int Area;
    int Per;
    public Rectangle(int length,int width){
        m_Length=length;
        m_Width=width;
    }
    
    public void getArea(){
        Area=m_Length*m_Width;
        System.out.println("面积为:"+Area);
    }
    public void getPer(){
        Per=(m_Length+m_Width)*2;
        System.out.println("周长为:"+Per);
    }
    public void showAll(){
        getArea();
        getPer();
    }
}
public class DaiMa {

    /**
     * @param args
     */
    public static void main(String[] args) {    
        Rectangle r=new Rectangle(2,3);
        r.showAll();
    }

public class Computer {
    char m_Clour;
    int m_CpuNum;
    public Computer(){}
    public Computer(char clour,int cpuNum){
        m_Clour=clour;
        m_CpuNum=cpuNum;
    }
    public void printComputer(){
        System.out.println("颜色为:"+m_Clour);
        System.out.println("CPU型号为:"+m_CpuNum);
    }
}
public class DaiMa {

    /**
     * @param args
     */
    public static void main(String[] args) {    
        Computer c1=new Computer();
        c1.m_Clour='黑';
        c1.m_CpuNum=9527;
        Computer c2=new Computer('白',12138);
        c1.printComputer();
        c2.printComputer();
    }
}    

posted @ 2021-05-25 15:47  计算机1902佟阳  阅读(46)  评论(0编辑  收藏  举报