import java.util.Scanner;

public class MoreArrays {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		//creating an array
		double[] data = {2.4, 5.6, 7.8, 9, 3};
		
		double[] data2 = new double[5];
		data2[0] = 2.4;
		data2[1] = 5.6;
		//.....
		
		for(int i = 0; i < data.length; i++) {
			double sum = data[i] + data2[i];
			System.out.printf("%.2f + %.2f = %.2f\n", data[i], data2[i], sum);
		}
		
		//call the method
		String[] words = readWords(input);
		System.out.printf("Entered %d words.\n", words.length);
		
		//use the other methods
		outputData(data);
		doubleData(data);
		outputData(data);
		outputData(data2);
		
		//assign the reference (not a copy)
		//new variable refers to same array
		double[] copyOfData = data;
		copyOfData[0] = -1200;
		outputData(copyOfData);
		outputData(data);
		
	} //end main
	
	//method to inputcreate an array of words
	// returns an array of Strings
	public static String[] readWords(Scanner in) {
		System.out.println("How many items?");
		int n = in.nextInt();
		
		//build the correct-sized array
		String[] result = new String[n];
		
		//fill in with words
		for(int i = 0; i < n; i++) {
			System.out.print("Enter a word: ");
			result[i] = in.next();
		}
		
		return result;
	}
	
	//parameter data is a reference type.
	public static void doubleData(double[] data) {
		//go through every item in the array
		for(int i = 0; i < data.length; i++) {
			data[i] = 2*data[i];
		}
	}
	
	public static void outputData(double[] data) { 
		for(int i = 0; i < data.length; i++) {
			System.out.printf("%5.2f ", data[i]);
		}
		System.out.println();
	}
	
}
