Friday July 28, 2000


Quiz 30 - Just Kidding!


On the Final Exam you can expect to see some of the same types of questions you saw on the first two exams.

For the coding portion you will be asked to give the algorithm you will use to solve the problem so make sure you remember how to do that. Also since we did not code the Binary Search you will not be asked to write that code but make sure you are familiar with the algorithm. Also make sure that you are familiar with at least one sorting technique.

For the Bonus question make sure you are familiar with the elimination method.

I do not have all of the program grades yet, but the breakdown that will be used is

First Program 4%
Second Program 4%
Third Program 6%
Fourth Program 6%

Gauss-Jordan Elimination

import java.io.*;

public class GaussJordan {
   double[][] coefficients;
   int rows;
   int columns;

   public GaussJordan(int rows) throws IOException {
      InputStreamReader stream = new InputStreamReader(System.in);
      BufferedReader keyboard = new BufferedReader(stream);

      this.rows = rows;
      columns = rows+1;

      coefficients = new double[rows][columns];

      for (int counter=0;counter < rows;counter++)
         for (int counter1=0;counter1 < columns;counter1++) {
            System.out.println("Please enter coefficients[" + counter + "][" + counter1 + "]");
            coefficients[counter][counter1] = new Double(keyboard.readLine()).doubleValue();
         }
   }

   public void display_contents() {
      String line="";

      for (int counter=0;counter < rows;counter++) {
         line = String.valueOf(coefficients[counter][0]);
         for (int counter1=1;counter1 < columns;counter1++)
            line += "\t" + String.valueOf(coefficients[counter][counter1]);
         System.out.println(line);
      }
   }

   public void elimination() {
      for (int rowcounter=0;rowcounter <rows;rowcounter++) {
         double temp = coefficients[rowcounter][rowcounter];
         for (int columncounter=0;columncounter < columns;columncounter++)
            coefficients[rowcounter][columncounter] /= temp;

         for (int counter=rowcounter+1;counter < rows;counter++) {
            temp = coefficients[counter][rowcounter];
            for (int columncounter=0;columncounter < columns;columncounter++)
               coefficients[counter][columncounter] += -1*temp*coefficients[rowcounter][columncounter];
         }
      }

      for (int rowcounter=rows-1;rowcounter > =0;rowcounter--)
         for (int counter=rowcounter-1;counter > =0;counter--) {
            double temp = coefficients[counter][rowcounter];
            for (int columncounter=0;columncounter < columns;columncounter++)
               coefficients[counter][columncounter] += -1*temp*coefficients[rowcounter][columncounter];
         }
   }

   public static void main(String[] args) throws IOException {
      GaussJordan myGaussJordan = new GaussJordan(3);

      myGaussJordan.elimination();

      myGaussJordan.display_contents();
   }
}