/*** Note this file doesn't compile.
     Please save it as figureskating.java and then
	 complete the three methods. You will be graded on
	 how thorough your tests are. Also, you'll replace the
	 statements return 0 and return null in the two methods.
	 Those are just placeholders in this empty framework.
***/

import java.util.*;

public class figureskating {
	
	public static void main(String[] args) {
	
		// Put tests here.
		
		double[] d1 = {2.2, 3.3, 1.1, 6.6};
		double[] d3 = {3.3, 6.6, 2.2, 1.1};
		double[] s1 = {6.1, 1.2, 8.8, 1.6};
		double[] s3 = {2.7, 9.1, 6.4, 5.8};
		double[] d2 = {2.3};
		double[] s2 = {1.7};
		
		// Five tests. We expect answers: 37.62, 81.29, 49.17, 89.43, 3.91
		System.out.println(judgeScore(d1,s1));
		System.out.println(judgeScore(d1,s3));
		System.out.println(judgeScore(d3,s1));
		System.out.println(judgeScore(d3,s3));
		System.out.println(judgeScore(d2,s2));
		
		double[] mys = {12.2, 1.3, 8.8, 9.7, 6.6, 8.9, 11.9, 7.5, 4.9, 10.2};
		for (int left=0; left<10; left++) {
			for (int right=0; left+right<10; right++) {
				double[] tmp = sanitizeScores(mys, left, right);
				System.out.print("low drop = "+left+" high drop = "+right+": ");
				print(tmp);
			}
		}
		
	}
	
	// For testing.
	public static void print(double[] vals) {
		for (int i=0; i<vals.length; i++)
			System.out.print(vals[i]+" ");
		System.out.println();
	}
	
	// Returns a judge's score for a routine where difficulties stores the
	// difficulties of each maneuver and scores stores the corresponding scores
	// the judge gave for each maneuver. Both arrays are guaranteed
	// to be the same size.
	public static double judgeScore(double[] difficulties, double[] scores) {
 
		// Just a dot product of the two "vectors".
		double res = 0;
		for (int i=0; i<difficulties.length; i++)
			res += difficulties[i]*scores[i];
		return res;
	}
	
	// Returns the remaining scores in sorted order after dropping numLowDrop
	// lowest scores and numHighDrop highest scores from allScores. No change
	// should be made to the allScores array.
	// You may asume that numLowDrop + numHighDrop < allScores.length.
	public static double[] sanitizeScores(double[] allScores, int numLowDrop, int numHighDrop) {
 
		// Because doubles are primitives, you don't need to do this and you can
		// instead use Arrays.copyOf.
		double[] mycopy = new double[allScores.length];
		for (int i=0; i<allScores.length; i++)
			mycopy[i] = allScores[i];
			
		// Sort this copy.
		Arrays.sort(mycopy);
		
		// Calculate size of my new array.
		int n = allScores.length - numLowDrop - numHighDrop;
		double[] res = new double[n];
		
		// Copy in the appropriate values and return.
		for (int i=0; i<n; i++)
			res[i] = mycopy[i+numLowDrop];
		return res;
			
	}
}