复数类
建立复数类。在课堂示例的基础上,显示复数时如果虚部为0时只显示实
部,实部为0时只显示虚部,虚部为负数时以a-bi的形式显示,并为复数类增加减
法功能。
public class pointtext {
public static void main(String[] args) {
// TODO Auto-generated method stub
Point p=new Point();
Point q=new Point(3,4,5);
p.show();
q.color=18;
q.show();
q.move(9,9);
System.out.println(Point.count);
System.out.println(Point.class);
}
}
class Point
{
int x;
int y;
static int color;
static int count=0;
Point() {
this(0,100,1);
}
Point(int x,int y,int color)
{
this.x=x;
this.y=y;
//this.color=color;
count++;
}
void show()
{
System.out.println("点为"+"("+x+","+y+")"+" "+"颜色"+color);
}
void move(int x1,int y1)
{
x=x1;
y=y1;
System.out.println("点为"+"("+x+","+y+")"+" "+"颜色"+color);
}
}