Java上机作业4.30
package ak; public class Point { int x; int y; void Ponit() { System.out.println(x); System.out.println(y); } void Ponit(int x0, int y0) { x = x0; y = y0; } void movePonit(int dx, int dy) { x += dx; y += dy; System.out.println("坐标是" + "(" + x + "," + y + ")"); } public static void main(String[] args) { Point p1 = new Point(); p1.x=1; p1.y=2; p1.movePonit(3, 4); Point p2 = new Point(); p2.x=11; p2.y=23 ; p2.movePonit(3,9); } }
package ak; public class Rectangle { int length; int width; public void getArea() { System.out.println(length * width); } public void getPer() { System.out.println((length + width) * 2); } public void getAll() { System.out.println("长是" + length); System.out.println("宽是" + width); System.out.println("面积是"); getArea(); System.out.println("周长是"); getPer(); } void Rectangle(int width1, int length1){ length=length1; width=width1; getAll(); } public static void main(String[] args) { Rectangle r1 = new Rectangle(); r1.Rectangle(4, 6); } }
package ak; public class Book { static int cpu; static char color; public static void all() { System.out.println("颜色是" + color); System.out.println("cpu是" + cpu); } static void book(int cpu1, char color1) { cpu = cpu1; color = color1; all(); } public static void main(String[] args) { Book r1 = new Book(); r1.color = '黑'; r1.cpu = 9100; r1.all(); book(9000, '白'); } }
package www; public class Person { double height; int age; String name; public void sayHello() { System.out.println("Hello,my name is "+name); } } package www; public class PersonCreate { public static void main(String[] args) { Person p1=new Person(); p1.age=34; p1.height=1.73; p1.name="zhangsan"; p1.sayHello(); Person p2=new Person(); p2.age=44; p2.height=1.74; p2.name="lishi"; p2.sayHello(); } }