// Need to import these classes
import java.util.HashMap;
import java.util.Arrays;

class Example {
	public static void main(String[] args){
		// Put the code for the example in its own method
		runExample();
	}

	// Method (function) to calculate the values. Need to specify int type for arguments
	private static double calcCR(int value, int valueCR){
		// Cast to double, and declare the result as a double
		double out = ((double)value)/valueCR;
		// Use power function in Math object
		out = Math.pow(out,2);
		// Handle special case using return statements inside if else
		if(out < 1.0){
			return 0.0;
		} else {
			return out;
		}
	}

	private static void runExample(){

		// Declare an array of ints		
		int[] a=new int[]{1,3,2,4,5,3,4,2,1};
		// The Map is not concise to declare or fill with values
		HashMap<Integer, Integer> b=new HashMap<>();
		b.put(1,2);
		b.put(2,1);
		b.put(3,4);
		b.put(4,2);
		b.put(5,3);

		// Declare output array
		double[] result = new double[a.length];
		// Java for loops require you to specify:
		// - initial values
		// - test to continue at the end of each iteration (like an until loop)
		// - changes to variables at each iteration
		for(int i=0; i<a.length;i++){
			// Cannot index into HashMap, use accessor function get()
			result[i]=calcCR(a[i],b.get(a[i]));
		}
		// Use Arrays.toString to get pretty array output
		System.out.println(Arrays.toString(result));

		// output:
		// [0.0, 0.0, 4.0, 4.0, 2.777777777777778, 0.0, 4.0, 4.0, 0.0]
	}
}

