Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4 (10 marks) We wish to compute the sum of all odd integers between n1 and n2 . Note that n1 and n2 are

image text in transcribedQuestion 4 (10 marks)

We wish to compute the sum of all odd integers between n1 and n2. Note that n1 and n2 are either, both long integers or both big integers and n2 is always greater than n1.

Compare the design using 5 different methods. The following UML diagram shows the five different methods:

(a) The 1st method, an iterative version, uses any type of loops and receives two long parameters

(b) The 2nd method, uses the LongStream in Lambda and stream, receives two long parameters

(c) The 3rd method, an iterative version, receives two BigInteger parameters and the return type is also a BigInteger

(d) The 4th method, a recursive version, receives two parameters of long types with long return type.

(e) The 5th method, a recursive version, receives two BigInteger parameters and the return type is also a BigInteger.

In the main method, generate two integers n1 and n2 make sure that n2 is greater than n1, invoke the 5 methods and display the results. Upon execution of your program, you will see the following sample output:

The name of the Java program is YourName_Supp_4.java and upload this Java file.

Question 4 (10 marks) We wish to compute the sum of all odd "integers" between n1 and n2. Note that n1 and n2 are either, both long integers or both "big" integers and n2 is always greater than n1. Compare the design using 5 different methods. The following UML diagram shows the five different methods: Supp_4 -static long sumOdd Mong n1, long n2) -static long sumOdd Llong n1, long n2) -static BigInteger sumOdd B(BigInteger n1, BigInteger n2) -static long sumOdd R(long n1, long n2) -static Biointeger sumOdd BR(BigInteger n1, BigInteger n2) + static void main(Stringl args) (a) The 1st method, an iterative version, uses any type of loops and receives two long parameters (b) The 2nd method, uses the LongStream in Lambda and stream, receives two long parameters () The 3rd method, an iterative version, receives two BigInteger parameters and the return type is also a BigInteger (d) The 4th method, a recursive version, receives two parameters of long types with long return type. (e) The 5th method, a recursive version, receives two BigInteger parameters and the return type is also a BigInteger. In the main method, generate two integers n1 and n2 make sure that n2 is greater than n1, invoke the 5 methods and display the results. Upon execution of your program, you will see the following sample output: The sum of all odd integers between 6404 and 6798 is (Iterative version) = 1300397 (Lambda version = 1300397 (BigInteger Iterative version) - 1300397 (Recursive version) = 1300397 (BigInteger Recursive version) = 1300397 The name of the Java program is YourName_Supp_4.java and upload this Java file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

Students also viewed these Databases questions

Question

Compare and contrast the duties held by a bank to its customers.

Answered: 1 week ago

Question

=+ Is the information source free from bias on the subject?

Answered: 1 week ago

Question

3. What are potential solutions?

Answered: 1 week ago