Computers and Technology

Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

4. The NumberProperties class contains methods used to determine various properties of numbers. You will write one method of the NumberProperties class.

public class NumberProperties
{
/** Returns true if num is a perfect square and false otherwise */
private static boolean isSquare(int num)
{ /* implementation not shown */ }

/** Returns true if num is a perfect cube and false otherwise */
private static boolean isCube(int num)
{ /* implementation not shown */ }

/** Returns the ratio of the sum of all the perfect cubes between start and end,
* inclusive, to the sum of all the perfect squares between start and end, inclusive,
* as described in part (a)
* Precondition: 1 <= start <= end <= Integer. MAX_VALUE
* There is at least one perfect square between start and end,
* inclusive.
*/
public static double (int start, int end)
{ /* to be implemented in part (a) */ }

// There may be variables and methods that are not shown.
}
(a) Write the method , which returns the ratio of the sum of all perfect cubes between start and end, inclusive, to the sum of all perfect squares between start and end, inclusive.

Two helper methods, isSquare and isCube, have been provided. The isSquare method returns true if its parameter is a perfect square and returns false otherwise. The isCube method returns true if its parameter is a perfect cube and returns false otherwise.

For example, of the numbers between 5
and 30
, inclusive, two are perfect cubes ( 8
and 27
) and three are perfect squares ( 9
, 16
, and 25
). The sum of the two perfect cubes is 35
and the sum of the three perfect squares is 50
. The method call NumberProperties.(5, 30) returns the ratio of the sums 35 and 50, which is 0.7.

You must use isSquare and isCube appropriately to receive full credit. Assume that there is at least one perfect square between start and end, inclusive.

Complete method .

/** Returns the ratio of the sum of all the perfect cubes between start and end, inclusive,
* to the sum of all the perfect squares between start and end, inclusive,
* as described in part (a)
* Precondition: 1 <= start <= end <= Integer. MAX_VALUE
* There is at least one perfect square between start and end, inclusive.
*/
public static double (int start, int end)
BoldItalicUnderline

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:00, 105001964
Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. after the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. declare any variables that are needed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system. in); is given.
Answers: 3
image
Computers and Technology, 23.06.2019 00:30, Thisisdifinite
Which of the following would you find on a network
Answers: 3
image
Computers and Technology, 24.06.2019 07:00, AnaiyaKirksey8
You are most likely to automatically encode information about
Answers: 1
image
Computers and Technology, 25.06.2019 04:30, Teedollasign
Which relativos possible when two tables share the same primary key? a.) one-to-one b.) one-to-many c.) many-to-one d.) many-to-many
Answers: 2
Do you know the correct answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Un...

Questions in other subjects:

Konu
Mathematics, 13.11.2019 19:31