Question: java Write a class FunWithLoops that contains the methods specified below. There is no constructor or instance variables. public int sumOdd(int value) Return the sum
java
Write a class FunWithLoops that contains the methods specified below. There is no constructor or instance variables.
public int sumOdd(int value) Return the sum of all the positive odd numbers less than the given value starting with 1. If value is less than or equal to 0, return 0. Use a loop
public double average(int count) Asks the user for count integers and returns the average of the integers. If count is 5, you will prompt the user 5 times to enter a number. Use prompts that look like these in the loop: Enter integer 1: Enter integer 2: ... Enter integer 5: If count is <= 0, return 0. (We do not want to divide by 0 ) The output might look something like this is, if count is 2
Enter integer 1: 25 Enter integer 2: 4 14.5
public double sumSeries(int value) Calculates the sum of the following series up to a value of n (n must be odd). (changed 10/10) 1 + 1/3 + 3/5 + 5/7 + ... (n-2)/n if n is less than or equal to 0 or is even, return 0. If n is 1, return 1.
No starter. No Javadoc
Use the following files:
FunWithLoopsRunner.java
/** * Tests the methods of the FunWithLoops class */ public class FunWithLoopsRunner { public static void main(String[] args) { FunWithLoops looper = new FunWithLoops(); System.out.println(looper.average(2)); System.out.println(looper.average(3)); } } FunWithLoopsTester.java
/** * Tests the methods of the FunWithLoops class */ public class FunWithLoopsTester { public static void main(String[] args) { FunWithLoops looper = new FunWithLoops(); System.out.println(looper.average(0)); System.out.println("Expected: 0.0"); System.out.println(looper.average(-2)); System.out.println("Expected: 0.0"); System.out.println(looper.sumSeries(0)); System.out.println("Expected: 0.0"); System.out.println(looper.sumSeries(1)); System.out.println("Expected: 1.0"); System.out.printf("%.5f%n", looper.sumSeries(5)); System.out.println("Expected: 1.93333"); System.out.printf("%.5f ",looper.sumSeries(7)); System.out.println("Expected: 2.64762"); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
