I am at the tail end of a 13-week college class for Java. It has gotten a lot more difficult the past couple of weeks. It was a miracle that I was able to do last week’s assignment. This week it is looking even worse. I had to email the professor for help. He gave me a paragraph explaining the concept of the assignment. I get all that. I wrote back to say that it’s the actual code I need help with. If anybody wants to help me out, that would be great.
"Using only the file Main.java, write a method called multiplier that includes a double array parameter and an int multiplier parameter (you can call this parameter multiply, or something other than multiplier).
Your method multiplier must multiply every element (or item) in the array by the integer parameter. Once each element has been changed, your method should return the new array that stores the new values. You must use a for loop to complete this task.
Some test cases are already included in the main method, but you are welcome to create your own."
Our code is to go at the end, beneath the comment, “//YOUR CODE HERE”.
class Main
{
public static void main(String[] args)
{
//feel free to test code here
//starter arrays
double arr1 [] = {0.5, 1.5, 2.5, 3.5, 4.5};
double arr2 [] = {12.3, 4.7, 8.1, 9.1, 6.8};
double arr3 [] = {-5.2, -0.9, 6.8, 10.0, 20.0};
//arrays to hold changed values
double arr1Changed [] = new double [arr1.length];
double arr2Changed [] = new double [arr2.length];
double arr3Changed [] = new double [arr3.length];
//assign changed value arrays to changed values
arr1Changed = multiplier(arr1, 2);
arr2Changed = multiplier(arr2, 5);
arr3Changed = multiplier(arr3, 3);
//display the new values
printArray(arr1Changed);
printArray(arr2Changed);
printArray(arr3Changed);
}//end main method
//method to make it easier to display array values
public static void printArray(double [] arr){
for(int i=0; i<arr.length; i++){
System.out.print( arr[i] + " ");
}
System.out.println();
System.out.println();
}//end printArray method
//YOUR CODE HERE
// write the method multiplier as described in the README.md file
public static double[] multiplier(double[] arr, int multiply) {
for(double i=0; i<arr.length; i++){
arr[i] = i*10;
}
}
}
The code I added is giving an error: “Type mismatch: cannot convert from double to int”. I don’t know why I’m getting that or what to do about it either. I have no idea what I’m doing.