Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method that will take an integer array and add all the elements of the array together and return this sum but with the

Write a method that will take an integer array and add all the elements of the array together and return this sum but with the following exceptions:

  • Exception 1: do not include any instances of 23 in the sum

  • Exception 2: do not include any numbers that come immediately before 23 in the sum

  • Exception 3: do not include any numbers that come immediately after 23 in the sum

See input/output example below:

Input

[5, 8, -2, 23, 9, 4]

[23, 1, 2, 23, 5, 7, -6]

Method Returns

17 (23 was not included because of exception 1) (9 and -2 were not included because it came immediately before and after 23) 5 + 8 + 4 = 17

1 (both 23s are not included in the sum) (1, 2 and 5 are immediately before or after the 23s so they are also not included.) 7 + (-6) = 1

This method should return an integer. Assume the arrays are not empty.

1.

Use the concept of method overloading to write another method (with the same name you used in part a) that achieves the same task but with a double array as the parameter this time. This method should return a double.

2.

Write a main method with at least two test cases each to test your methods. You may use (copy and paste them into your class) the printArray() methods from the quiz sample problem set solutions (found on Brightspace homepage) as helper methods. You may hard code your test cases. In other words, you do not need to read anything from user input. Just make up a couple of appropriate test cases to call your methods. Check the rubric for details on whats expected of your test case communication.

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions