/** This is a Supporting Class which has Rho/Theta values in a method to be added * into an ArrayList. Once added, it will calculate the values of * X and Y. Main will then print each of the X/Y 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://math.ucsd.edu/~wgarner/math4c/textbook/chapter9/polar_coordinates.htm * http://math.ucsd.edu/~wgarner/math4c/derivations/distance/distancepolar.htm * * @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.util.*; import java.text.*; public class Polar { private double rho; // hypothneus private double theta; // degree private List arrList = new ArrayList(); private List rhoList = new ArrayList(); private List thetaList = new ArrayList(); private List dist = new ArrayList(); private DecimalFormat df = new DecimalFormat("####.00000000"); public Polar () { arrList = new ArrayList(); rhoList = new ArrayList(); thetaList = new ArrayList(); dist = new ArrayList(); } public List getRho() { return rhoList; } public List getTheta() { return thetaList; } public void addXY(){ this.arrList.add("86.92 2.47"); this.arrList.add("70.93 27.81"); this.arrList.add("97.74 34.36"); this.arrList.add("30.90 35.14"); this.arrList.add("51.66 31.70"); this.arrList.add("0.830 21.77"); this.arrList.add("55.91 66.62"); this.arrList.add("32.92 75.23"); this.arrList.add("65.26 72.53"); this.arrList.add("83.90 4.710"); } public void printValues() { for (int i = 0; i < arrList.size(); i++) { // loop through arraylist String item = arrList.get(i); // grab element from arraylist System.out.println("Item " + i + " : " + item); // printout its element } } public void printRhoThetaValues() { for (int i = 0; i < rhoList.size(); i++) { Double rItem = rhoList.get(i); Double tItem = thetaList.get(i); System.out.println( i + "\t" + "Rho: " + rItem + " Theta: " + tItem); } } public void printDistanceResults() { System.out.println(); for (int i = 0; i < dist.size(); i++) { // loop through the distance arraylist String item = df.format(dist.get(i)); // grab dist element in the arraylist System.out.println("Distance " + i + " : " + item); // print out its values / elements in the dist arraylist } } public void calRho() { String item = ""; String [] ele; for ( int c=0; c