<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
   Purpose:
     To read in a two-dimensional vector in magnitude &amp; angle form,
     and convert it into rectangular form.

   Record of revisions:
       Date       Programmer          Description of change
       ====       ==========          =====================
      4/01/99    S. J. Chapman        Original code
  
*/
import chapman.io.*;
public class PolarToRect {

   // Define the main method
   public static void main(String[] args) {

      // Final variables
      final double deg2Rad = Math.PI/180;  // Conversion factor

      // Declare variables, and define each variable
      double[] polar;      // Array containing magnitude / angle
                           //   polar[0] contains magnitude
                           //   polar[1] contains angle in degrees
      double[] rect;       // Array containing rectangular comps

      // Create StdIn object
      StdIn in = new StdIn();

      // Create arrays
      polar = new double[2];
      rect = new double[2];

      // Get magnitude and angle
      System.out.print("Enter magnitude of vector: ");
      polar[0] = in.readDouble();
      System.out.print("Enter angle of vector (in degrees): ");
      polar[1] = in.readDouble();

      // Convert to rectangular form.
      rect[0] = polar[0] * Math.cos( polar[1] * deg2Rad );
      rect[1] = polar[0] * Math.sin( polar[1] * deg2Rad );
 
      // Write out result.
      Fmt.printf("The rectangular form is %9.5fi + ", rect[0]);
      Fmt.printf("%9.5fj\n",rect[1]);
   }
}
</pre></body></html>