Background info:
----------------------------------------------------------------
public class Point {
protected int x;
protected int y;
public Point(){
this.x = x;
this.y = y;
}
public String toString(){
return "" + x + " , " + y;
}
}
---------------------------------------------------------------
public class PointName extends Point {
private String name;
public PointName(String name, int x, int y){
super();
this.name = name;
}
public PointName() {
// TODO Auto-generated constructor stub
}
public String toString(){
return name + super.toString();
}
}
------------------------------------------------------------------------
我想创建一个名为最近点的应用程序,并且在此类中,数据是从标准输入(键盘)提供的。然后我想提供 10 个点(给定点的名称),这些点将存储在一个向量中。然后将它们打印出来。在此之后还有一点,但我陷入了这个阶段,因为我不知道该怎么做。我欢迎所有可能的解决方案!!
到目前为止我的解决方案:
public class ClosestPoint {
public static void main (String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Write in the new point starting with name then x, y");
String name = "";
Integer x = 0;
Integer y = 0;
String nameGivenPoints[] = null; // List of points to create
String line = in.nextLine(); // info from the board
while(!line.endsWith("")){
nameGivenPoints = line.split("\r\n\r");
name = nameGivenPoints[0];
x = Integer.parseInt(nameGivenPoints[1]);
y = Integer.parseInt(nameGivenPoints[2]);
// Maybe a forloop here
PointName tenDifferentPunkts = new PointName(name, x, y);
System.out.println(tenDifferentPunkts.toString());
line = in.nextLine();
}
}