/** This is a Supporting Class which has XY values in a method to be added * into an ArrayList. Once added, it will calculate the values of * Rho and Theta. Main will then print each of the Rho/theta values to stdout * and calculate its distances. After Distance has been computed, it will print * out its values. * * http://www.mathsisfun.com/polar-cartesian-coordinates.html * http://hotmath.com/hotmath_help/topics/distance-formula.html * * @author Freeman Lo * @version 0.0.1 Build 1 Feb 1, 2014. * Limitations - Besides not having try-catch error handling blocks * Everything else seem to work pretty well, it is a standalone software * with embedded values in each Cartesian and Polar class. * */ import java.io.*; import java.text.DecimalFormat; import java.util.*; import java.lang.*; public class Cartesian { private double x; // distance private double y; // degree private List arrList = new ArrayList(); private List xList = new ArrayList(); private List yList = new ArrayList(); private List dist = new ArrayList(); private DecimalFormat df = new DecimalFormat("####.00000000"); public Cartesian () { arrList = new ArrayList(); xList = new ArrayList(); yList = new ArrayList(); dist = new ArrayList(); } public List getX() { return xList; } public List getY() { return yList; } public void addPolar(){ this.arrList.add("86.95508783 1.6277324"); this.arrList.add("76.18701333 21.40898834"); this.arrList.add("103.60365438 19.36886532"); this.arrList.add("46.79347818 48.6735483"); this.arrList.add("60.61060633 31.53442567"); this.arrList.add("21.78581649 87.81660656"); this.arrList.add("86.97213634 49.99536595"); this.arrList.add("82.11747256 66.36622756"); this.arrList.add("97.56776363 48.02020788"); this.arrList.add("84.0321016 3.21311281"); } public void printValues() { for (int i = 0; i < arrList.size(); i++) { String item = arrList.get(i); System.out.println("Item " + i + " : " + item); } } public void printXYValues() { for (int i = 0; i < xList.size(); i++) { Double x = xList.get(i); Double y = yList.get(i); System.out.println( i + "\t" + "X: " + df.format(x) + " Y: " + df.format(y)); } } public void printDistanceResults() { System.out.println(); for (int i = 0; i < this.dist.size(); i++) { String item = df.format(this.dist.get(i)); System.out.println("Distance " + i + " : " + item); } } public void calX() { String item = ""; String [] ele; for ( int c=0; c