Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1. Write a program that includes a method public static double average(int n) { // instructions go here } This method reads n integers from the keyboard and returns the average of those numbers rounded to two decimal places Include a main method that: 1. prompts for n 2. calls the method, passing n to average(...) 3. prints the average of n numbers 2. Write a program that includes a method that accepts two doubles that represent the two legs of a right triangle and returns the hypotenuse. In the main method , prompt for two numbers and send these numbers to the method. Print the hypotenuse. Remember c = √ a*a + b*b (Pythagorean Theorem). Uses the Java method Math.sqrt(double x) to calculate square root. 3. The Consumer Price Index (CPI) represents the change in the prices paid by urban consumers for a representative basket of goods and services. It is a percentage value rounded to the nearest tenth, for example, 9.2 or –0.7. Write a method public static double getCPI() that requests a user to enter a number (double) between -20 and 20. If the user supplies number outside of this range, the method should display an appropriate error message, (“number too high,” “ number too low,” or “number has wrong precision”) and prompt the user for another value. When the user succeeds, the method should return that (valid) number. Test your method by continually prompting a user for a value and displaying the value. When you are confident that the method is correct, write a second method public static double inflation( double cpi, double expenses) that accepts the CPI and last year’s annual expenses. Method inflation(...) returns what you might expect to pay for the same goods in the coming year. Write a main(...) method that calls both getCPI() and inflation(...).