Question
public class Homework1 { /** * minValue returns the minimum value in an array of doubles. You can assume * the array is nonempty and
public class Homework1 {
/**
* minValue returns the minimum value in an array of doubles. You can assume
* the array is nonempty and has no duplicates. Your solution must go
* through the array exactly once. Your solution must not call any other
* functions. Here are some examples (using "==" informally):
*
*
* -7 == minValue (new double[] { 1, -4, -7, 7, 8, 11 })
*
*/
public static double minValue (double[] list) {
return 0; //TODO: fix this with your code
}
/**
* minPosition returns the position of the minimum value in an array of
* doubles. The first position in an array is 0 and the last is the
* array.length-1.
*
* You can assume the array is nonempty and has no duplicates. Your solution
* must go through the array exactly once. Your solution must not call any
* other functions. Here are some examples (using "==" informally):
*
*
* 0 == minPosition(new double[] { -13, -4, -7, 7, 8, 11 })
*
*/
public static int minPosition (double[] list) {
return 0; //TODO: fix this with your code
}
/**
* distanceBetweenMinAndMax returns difference between the minPosition and
* the maxPosition in an array of doubles.
*
* You can assume the array is nonempty and has no duplicates. Your solution
* must go through the array exactly once. Your solution must not call any
* other functions. Here are some examples (using "==" informally):
*
*
* 1 == distanceBetweenMinAndMax(new double[] { 1, -4, -7, 7, 8, 11, -9 }) // -9,11
*
*/
public static int distanceBetweenMinAndMax (double[] list) {
return 0; //TODO: fix this with your code
}
/**
* The following tests below should pass if your methods above are correct.
* It is required for you to write 5 more tests for each method to ensure your
* methods above are written correctly.
*/
public static void main(String[] args) {
// minValue Test sample
double minValue = minValue (new double[] { 1, -4, -7, 7, 8, 11 });
if (minValue == -7) {
System.out.println("The minValue test was successful.");
} else {
System.out.println("The minValue test was not successful.");
}
// minPosition Test sample
double minPosition = minPosition(new double[] { -13, -4, -7, 7, 8, 11 });
if (minPosition == 0) {
System.out.println("The minPosition test was successful.");
} else {
System.out.println("The minPosition test was not successful.");
}
// distanceBetweenMinAndMax Test sample
double distance = distanceBetweenMinAndMax(new double[] { 1, -4, -7, 7, 8, 11, -9 });
if (distance == 1) {
System.out.println("The distanceBetweenMinAndMax test was successful.");
} else {
System.out.println("The distanceBetweenMinAndMax test was not successful.");
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started