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();
}
}
------------------------------------------------------------------------
I want to create an application called closest point and in this class data is supplied from the standard input(keyboard). Then i want to supply 10 points (name given points) which will be stored in a vector. Then print them out. A bit more after this but im stuck in this stage as i dont know what to do. I welcome all possible solutions!!
MY SOLUTION SO FAR:
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();
}
}
Try this:
PointName.java:
ClosestPoint.java: