How do you create an excel file?
I've been trying out making the infamous Point class, along with a program to check the distances between some.
The program:
Code:
import java.io.*;
class TestDistance {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int i,j;
double temp;
Point p[] = new Point[5];
System.out.println("Enter the coordinates");
for (i = 0; i < p.length; i++) {
System.out.print("Point" + (i + 1) + ":(x):");
temp = Double.parseDouble(in.readLine());
System.out.print(" (y):");
p[i] = new Point(temp, Double.parseDouble(in.readLine()));
}
double distances[][] = new double[p.length][p.length];
for (i = 0; i < p.length; i++) {
for (j = 0; j < p.length; j++) {
distances[i][j] = p[i].distance(p[j]);
}
}
}
}
The Point class:
Code:
class Point {
private double x;
private double y;
public Point(double getx, double gety) {
x = getx;
y = gety;
}
public double GetX() {
return x;
}
public double GetY() {
return y;
}
public void SetX(int myx) {
x = myx;
}
public void SetY(int myy) {
y = myy;
}
public boolean equals(Point p) {
return (x == p.GetX() && y == p.GetY());
}
public double distance(Point p) {
double distancex = (p.GetX() - x);
double distancey = (p.GetY() - y);
return Math.sqrt(Math.pow(distancex, 2) + Math.pow(distancey, 2));
}
public String toString() {
return("(" + x + ", " + y + ")");
}
}
I want to display the distances array, but don't get me started about the command prompt. It is very frustrating being able to easily create an array like that, but not being able to display it properly.
So is there any way to let java save the array in an excel file?
PS: I couldn't find a search function on this forum, so I don't know if this question has been asked already.