All pastes #279199 Raw Edit

Stuff

public text v1 · immutable
·published 2006-12-14 21:37 UTC
rendered paste body
public class Kompressori {

	public static void main(String[] args) {
		double[] syotetaulukko = {1.0, 2.0, 1.4, 1.5, 3.0};
		double[] uudet = kompressoituna(syotetaulukko, 1.8, 0.9);
		for (int i = 0; i < uudet.length; i++)
			System.out.println(i+1 + ": " + uudet[i]);
	}

	/**
	 * Kertoo voimakkuudet kertoimella mikäli raja ylittyy.
	 * 
	 * AE: voimakkuudet != null
	 *     && raja != null
	 *     && kerroin != null
	 */
	public static void kompressoi(double[] voimakkuudet, double raja, double kerroin) {
		for (int i = 0; i < voimakkuudet.length; i++) {
			if (voimakkuudet[i] > raja)
				voimakkuudet[i] = voimakkuudet[i] * kerroin;
		}
	}

	/**
	 * Palauttaa kompressoidun voimakkuudet-taulukon.
	 *
	 * AE: voimakkuudet != null
	 *     && raja != null
	 *     && kerroin != null
	 */
	public static double[] kompressoituna(double[] voimakkuudet, double raja, double kerroin) {
		double[] taulukko = voimakkuudet;
		kompressoi(taulukko, raja, kerroin);
		return taulukko;
	}

}