# Write a method sumOfSquares which takes a positive integer n and returns the sum of the squares…

Write the following Java methods and appropriate code to test them.

a) Write a method sumOfSquares which takes a positive integer n and returns the sum of the squares from 1^2 up

to n^2. For example, sumOfSquares(4) returns 30, since 1^2 + 2^2 + 3^2 + 4^2 = 1 + 4 + 9 + 16 = 30. Do not use a

formula to do this. Instead, add each term in a “for” loop.

b) Pretend that you don’t have the multiplication operator available. Write a method product that takes two integers

x and y and returns their product.

c) Write a method compoundInterest(double money, double interestRate, int years) that takes an amount of money,

a yearly interest rate, and a number of years, and returns the total amount of money after that number of years. For

example, compoundInterest(1000, 0.05, 3) returns 1157.625 (it’s the total amount of money that you get if you

deposit 1000 dollars with an interest rate of 5% for 3 years). Do not use Math.pow() to do this. Instead, add each

term in a “for” loop.

d) Write a method polySpiralLength(int n, double base, int rounds) that returns the total length of a polyspiral like

those you implemented in a previous homework (HW1).

Attachments:

### Looking for a similar assignment? Get help from our qualified experts!

"Our Prices Start at $9.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!":

Order a Similar Paper Order a Different Paper