Question: Problem 1: This will be a program that will use loops to do computations. a) Create a class called Computations. There should not be a

Problem 1: This will be a program that will use loops to do computations.

a) Create a class called Computations. There should not be a constructor or any instance variables.

b) Create a method called computeEvenSums with an integer argument called stop. Inside the method create a local integer variable named sum and set it to 0. This should be outside the loop. Create a for loop that begins at 2 and ends at stop. It should be incremented by 2. Add the increment to sum. The first time through the increment should be 2 and the sum will be 2. The second time through the loop the increment will be 4 and the sum will be 6. End the loop. Return sum. Be careful and not test this with a large stop value.

c) Create a method called sumAllSquares with an integer argument called stop. Inside the method create a local integer variable named sum and set it to 0. Create an another integer variable named square and set it to 0. These variables should be outside the loop. Create a for loop that begins at 1 and ends at stop. It should be incremented by 1. Inside the loop, square the increment variable each time the loop is executed and assign it to square. For example, assuming you are using x for your increment the code should be square = x*x; Add square to sum. End the loop. Return sum. Be careful and not test this with a large stop value.

d) Create a method called computeOddSums with two integer arguments one called start and one called stop. Inside the method create a local integer variable named sum and set it to 0. This should be outside the loop. Create a for loop that begins at start and ends at stop. It should be incremented by 2. Add the increment to sum. The first time through the increment should be the start value and the sum will be the start value. The second time through the loop the increment will be the start value and 2. End the loop. Return sum. Be careful and not test this with a large stop value.

e) Create a method called calculateAllPowers with an integer argument called stop. Create a double variable named power and assign it a 0. Create a for loop that runs from 0 and ends at stop. Increment the loop by 1. Inside the loop, raise 2 to a power. Use the increment as the power. And assign it to power. For example, power = Math.pow(2,i); Print Two raised to the + i + power is: + power; End the loop. Do not return anything.

f) Create a tester class name ComputationTester.

g) Import Scanner

h) Create a main

i) Create a Scanner object.

j) Create a Computations object.

k) Ask the user to input the value to stop computing even numbers. Remind them to make the number stop at an even value. Call the receiving variable end.

l) Create an integer variable named sum and set it to 0.

m) Call the method sumAllEven and assign it to sum.

n) Print the result with word something like The sums of all even numbers from 0 to " + end + "is: " + sums + " "

o) Ask the user to input the value to stop computing the sum of the squares. Use the end variable.

p) Call the method sumOfSquares and assign it to sum.

q) Repeat n with the appropriate wording.

r) Ask the user to input the value to start computing all odd values. Create a begin variable to receive the value.

s) Ask the user to input the value to stop computing all odd values. Use the end variable.

t) Call the method computeOddSums and assign it to sum.

u) Repeat n with the appropriate wording.

v) Ask the user to input the value to stop computing the squares. Use the end variable.

w) Call the method calculateAllPowers.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!