package Wxte; import java.util.Scanner; public class Person { int x; int y; Person() { } Person(int dx,int dy) { x+=dx; y+=dy; } void movepoint(int p1,int p2) { p1=x*2; p2=y*2; System.out.println("p1的坐标"+p1+" "+"p2的坐标"+p2); } }
package Wxte; import java.util.Random; import java.util.Scanner; public class Mast { public static void main(String[] args) { // TODO Auto-generated method stub Person p=new Person(); p.x=6; p.y=7; p.movepoint(p.x,p.y); } }
2.
package Wxte; import java.util.Scanner; public class Person { int length; int width; public Person(int length, int width) { this.length = length; this.width = width; } public int getArea() { return length * width; } public int getPer() { return 2 * (length + width); } void showAll() { System.out.println("长为" + length + ",宽为" + width + ",面积为" + getArea() + ",周长为" + getPer()); } public static void main(String[] args) { Person a = new Person(5 ,3); a.showAll(); } }
3.
package Wxte; import java.util.Scanner; public class Person { char color; int model; Person(){ } Person(char color,int model){ this.color=color; this.model=model; } public void info() { System.out.println("笔记本信息:"+color+" "+model); } }
package Wxte; import java.util.Random; import java.util.Scanner; public class Mast { public static void main(String[] args) { // TODO Auto-generated method stub Person a=new Person('蓝',16); a.info(); } }
4.
package Wxte; import java.util.Scanner; public class Person { private String name; private int age; private float heigh; public Person(String name,int age,float heigh) { this.name=name; this.age=age; this.heigh=heigh; } public void sayHello() { System.out.println("hello,my name is "+name+" 我的年龄为"+age+" 我的身高为"+heigh+"cm"); } }
package Wxte; import java.util.Random; import java.util.Scanner; public class Mast { public static void main(String[] args) { // TODO Auto-generated method stub Person p =new Person("张三",34,175); Person m =new Person("李四",46,177); p.sayHello(); m.sayHello(); } }