package rebelsky.arrays; import java.io.PrintWriter; /** * Some fun with grading, intended as an example of arrays. * * @author CSC152 * @version 1.0 of October 2004 */ public class Grading { public static void main(String[] args) { PrintWriter pen = new PrintWriter(System.out, true); double[] grades = { 61.2, 78.0, 70.0, 50.0, 67.0, 22.3 }; // Print out the grades. for (int i = 0; i < grades.length; i++) pen.println("Original grade " + i + ": " + grades[i]); // Find the largest grade // (a) Make an assumption about the biggest double biggest = grades[0]; // (b) Look at each remaining element for (int i = 1; i < grades.length; i++) { // (i) Update our assumption if the ith grade // is higher (Compare the biggest so far // with the ith grade.) if (grades[i] > biggest) biggest = grades[i]; } pen.println("The largest grade is " + biggest); // Recompute the grades (as ratio of that grade to largest grade) for (int i = 0; i < grades.length; i++) { // Set each one to previous value divided by biggest // And multiply by 100 grades[i] = 100*grades[i]/biggest; } // for // Print out the new grades. for (int i = 0; i < grades.length; i++) pen.println("New grade " + i + ": " + grades[i]); } // main(String[]) } // class Grading