📄 useline.java
字号:
/**
* Java语言实验参考程序
* Company 北京师范大学计算机系
* @author 孙一林
* @version 1.0
*/
class Point { // 声明一个“点”类
private int x0; // 定义坐标原点
private int y0;
private int x; // 定义“点”的X坐标
private int y; // 定义“点”的Y坐标
public Point() { // 定义“点”类的构造方法
this.x0 = 0;
this.y0 = 0;
this.x = 0;
this.y = 0;
}
public Point(int newX0,int newY0) { // 定义“点”类的构造方法
this.x0 = newX0;
this.y0 = newY0;
this.x = newX0;
this.y = newX0;
}
public void setX(int newX) { // 重新设置“点”的X坐标
x = newX + x0;
}
public int getX() { // 获取“点”的X坐标
return x;
}
public void setY(int newY) { // 重新设置“点”的Y坐标
y = newY + y0;
}
public int getY() { // 获取“点”的Y坐标
return y;
}
}
class Line extends Point {
private int x0; // 定义坐标原点
private int y0;
private int x2; // 定义“线”的另一个端点的X坐标
private int y2; // 定义“线”的另一个端点的Y坐标
public Line() { // 定义“线”的构造方法
super(); // 调用父类的构造方法
this.x0 = 0;
this.y0 = 0;
x2 = 0;
y2 = 0;
}
public Line(int newX0,int newY0) { // 定义“线”的构造方法
super(newX0, newY0); // 调用父类的构造方法
this.x0 = newX0;
this.y0 = newY0;
x2 = x0;
y2 = x0;
}
public void setX2(int newX2) { // 重新设置第二个“点”的X坐标
x2 = newX2 + x0;
}
public int getX2() { // 获取第二个“点”的X坐标
return x2;
}
public void setY2(int newY2) { // 重新设置第二个“点”的Y坐标
y2 = newY2 + y0;
}
public int getY2() { // 获取第二个“点”的Y坐标
return y2;
}
}
public class UseLine {
public static void main(String[] args) {
Line line1 = new Line(); // 创建第一条“线”的对象(line1)
line1.setX(20); // 移动“线”的第一个端点
line1.setY(10); // 调用“线”类父类的方法
line1.setX2(40); // 移动“线”的第二个端点
line1.setY2(20);
System.out.println("X1 = " + line1.getX());
System.out.println("Y1 = " + line1.getY());
System.out.println("X2 = " + line1.getX2());
System.out.println("Y2 = " + line1.getY2());
Line line2 = new Line(10,10); // 创建第二条“线”的对象(line2)
line2.setX(20); // 移动“线”的第二个端点
line2.setY(10);
line2.setX2(40);
line2.setY2(20);
System.out.println("X1 = " + line2.getX());
System.out.println("Y1 = " + line2.getY());
System.out.println("X2 = " + line2.getX2());
System.out.println("Y2 = " + line2.getY2());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -