编写一个java程序,是一个MyPoint类,该类拥有横、纵坐标两个属性,定义构造方法来初始化类的这些属性,定义方法输出MyPoint的信息。编写应用程序使用MyPoint。 【输入形式】 Please input the horizontal (X) : Please input the ordinate (Y) : 【输出形式】 Your location of horizontal (X) is : Your location of ordinate (Y) is : 【输入样例】 30.5 75.6 【输出样例】 30.5 75.6
时间: 2023-06-17 17:08:39 浏览: 92
以下是代码实现:
```java
import java.util.Scanner;
public class MyPoint {
private double x;
private double y;
public MyPoint(double x, double y) {
this.x = x;
this.y = y;
}
public void printInfo() {
System.out.println("Your location of horizontal (X) is : " + x);
System.out.println("Your location of ordinate (Y) is : " + y);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please input the horizontal (X) : ");
double x = scanner.nextDouble();
System.out.print("Please input the ordinate (Y) : ");
double y = scanner.nextDouble();
MyPoint point = new MyPoint(x, y);
point.printInfo();
}
}
```
运行结果:
```
Please input the horizontal (X) : 30.5
Please input the ordinate (Y) : 75.6
Your location of horizontal (X) is : 30.5
Your location of ordinate (Y) is : 75.6
```
阅读全文