I have been busting my brain for days trying to complete this Java project and for the life of me I cannot get it to run. Here is what I am supposed to do:
Write a program that calls each of the methods of the Math class from the list below and provides output showing the method called, values sent to the method, and the returned results. Each listed method will tell you which values to use. For example:
Listed method: double pow(double a, double b): use 2.0 and 3.0 Your program would display: Math.pow(2.0, 3.0) = 8.0 When calling a method that accepts doubles, use numbers with at least one decimal digit like the example above, even if it's a zero. Remember that numbers with decimals are double literals. Try to use values that will produce easily verifiable results.
Here is the list:
double pow(double a, double b): Use 3.0 and 2.0 double sqrt(double x): Use 25.0 int max(int a, int b): Use 6 and 2 double max(double a, double b): Use -50.0 and 7.0 static double random()
Sample output: Math.pow(3.0, 2.0) = 9.0 Math.sqrt(25.0)=5.0 Math.max(6,2)=6 Math.max(-50.0,7.0)=7.0 Math.random()= -random value-
Test your program with the values shown in the examples, fix any errors.
Add a method to your program called randomStudy that has no parameters and returns no value. In this method, do the following:
a. Declare three int variables: total, min, and max. Set total to 0, min to 11, andmax to -1. b. Create a loop that will run 1,000 times. In the body of the loop, generate a random int value between 1 and 10, inclusive. Add this number to your total. If this number is less than min, update min with the new number. If it is greater than max, update max with the new number. c. After the loop, display the following:
Min value: x Max value: y Average: z
Replace x and y with your min and max values. Calculate z by dividing your total by 1000d.
Call your new randomStudy method from the main method.
Highlight and copy the output shown in Eclipse. Paste the output at the bottom of your source code file. Add the text Results:above your output, and then comment out the text your just dded plus the output text. Your commented results should look something like this:
/* Results: Math.pow(3.0, 2.0)= 9.0 Math.sqrt(25.0) = 5.0 Math.max(6, 2) = 6 Math.max(-50.0, 7.0) = 7.0 Math.random() = -random number- Min value: 1 Max value: 10 Average: 5.553 */
public class Method { public void main(String[] args) { public static double pow(double 3.0, double 2.0); public static double sqrt(double 25); public static int max(int 6, int 2); public static double max(double -50, double 7) public static double random() } } public class randomStudy{
public void main(String[] args) {
int min = 11;
int max = -1;
int total = 0;
int i;
for(i = 0; i < 1000; i++){
int randomInt = (int)(11.0 * Math.random());
System.out.println("Random integer between 1 and 10 : " + randomInt );
int newtotal = (randomInt + int total);
if int newtotal < int min {
int min = Math.random());
}
else{
System.out.println("int min");
}
if int newtotal > max {
int max = Math.random());
}
else{
System.out.println("int max");
}
}
System.out.println("Min value:" + int min);
System.out.println("Max Value:" + int max);
System.out.println("Average:"+ int newtotal / 1000d);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method pow(double, double) is undefined for the type Math The method pow(double, double) is undefined for the type Math at Math.main(Math.java:3)
^ Recieve this error.
Aucun commentaire:
Enregistrer un commentaire