Question: I need help with a java assignment You are writing an object that is a list of numbers on which you are able to some

I need help with a java assignment

You are writing an object that is a list of numbers on which you are able to some simple mathematical computations. Please note that all of the indicies that will be passed to you will be valid; you don't have to write error checking code. However, you will have to handle the case where you create a fresh object and call the appropriate methods (e.g. sumOfAllOddNumbers).

The object to implement this is referred to as SumFun and consists of the following public methods:

public SumFun()

public void addToList(int i) - Add an integer to our list of integers.

public int sumOfAllEvenNumbers() - Returns the sum of all even numbers in the list.

public int sumOfEvenNumbers(int start, int end) - Returns the sum of all even numbers from the start index (given by start) and the end index (given by end). Note that it includes both the start and end indices.

public int sumOfAllOddNumbers() - Returns the sum of all odd numbers in the list.

public int sumOfOddNumbers(int start, int end) - Returns the sum of all even numbers from the start index (given by start) and the end index (given by end). Note that it includes both the start and end indicies.

public int sumOfOddDigitsForItem(int itemIndex) - Given an index into the list you extract the number and then add all of the odd digits. For example, if you have the number 1234 the sum of the odd digits is 1 + 3 = 4.

Your Program.java should contain code to test your SumFunobject. Load multiple values and check to make sure that the values match the expected values. Use looping to load and test your object.

Getting Started

We are going to do this exercise by writing the object that solves the problem first (in a source file called SumFun.java) and then testing it using code we write into Program.java. Using the techniques shown on the web page titled "How to Start Every Project in this Class" create a source file called SumFun.java as well as a file called Program.java.

There is no code to copy for the assignment. You get to do it all! Don't forget to provide proper Javadoc documentation.

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!