/*
   Purpose:
     To calculate the dot product of two vectors.

   Record of revisions:
       Date       Programmer          Description of change
       ====       ==========          =====================
      4/01/99    S. J. Chapman        Original code
  
*/
import chapman.io.*;
public class DotProduct {

   // Define the main method
   public static void main(String[] args) {

      // Declare variables, and define each variable
      double dotProduct = 0; // Dot product
      int i;                 // Loop Index
      double[] v1;           // Vector 1
      double[] v2;           // Vector 2

      // Create StdIn object
      StdIn in = new StdIn();

      // Create vectors
      v1 = new double[3];
      v2 = new double[3];

      // Print banner
      System.out.println("This program calculates the dot "
                       + "product of two vectors.");

      // Get vector 1
      for ( i = 0; i < v1.length; i++ ) {
         System.out.print("Enter element " +(i+1) + " of v1: ");
         v1[i] = in.readDouble();
      }
         
      // Get vector 2
      for ( i = 0; i < v2.length; i++ ) {
         System.out.print("Enter element " +(i+1) + " of v2: ");
         v2[i] = in.readDouble();
      }
         
      // Calculate dot product
      for ( i = 0; i < v1.length; i++ )  
         dotProduct += v1[i] * v2[i];
      
      // Write out result.
      System.out.print("The dot product of v1 and v2 is " 
                       + dotProduct);
   }
}
