Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Update: Jan 2 3 rd 1 1 am: The two source files linked below ( ArrayLibrary . java and ArrayLibraryTest.java ) were wrong. Please download

Update:
Jan 23rd 11am: The two source files linked below (ArrayLibrary.java and ArrayLibraryTest.java) were wrong. Please download them again.
You just submit your code to Web-CAT to be graded.
Learning objective:
gain practice with JUnit test cases
gain familiarity with CCI Style Guide
write code using arrays
Project 1
You have to write a static class that has operations on arrays of integers. Each method does one specific action. All of the methods take at least one argument (nums), an array of integers and return some value. All methods should check that the array argument nums is not null before accessing it. In addition, the nums argument might be an array of 0 elements.
The methods you must implement are:
int findLargest(int nums[])
returns the index to the largest number in nums or -1 if the array is either empty or null
int findSmallest(int nums[])
returns the index to the smallest number in nums or -1 if the array is either empty or null
boolean isContained(int nums[], int x)
returns true if x is found in the nums array or false if the element x is not found or the array is either empty or null
boolean appearsMultipleTimes(int nums[], int x)
returns true if x is found multiple times in the nums array. Returns false if x is not found multiple times or the array is either empty or null
boolean hasDuplicates(int nums[])
returns true if the array nums contains at least one element that appears more than once in the array (i.e., there is a duplicate). Should return false otherwise or if the array is either empty or null
int sumAll(int nums[])
returns the sum of all values in the nums array. Should return 0 if the array is either empty or null
double average(int nums[])
returns the sum of all numbers in the array divided by the number of elements in the array (i.e., the average). Should return Double.NaN (not a number) if the array is null or has 0 elements (in which case you can't divide by 0).
Example of how to use ArrayLibrary
// Driver method, use to make sure things compile.
public static void main(String args[])
{
int[] nums ={10,4,50,128,-1,49};
int result;
result = ArrayLibrary.findLargest(nums);
System.out.println("Largest value is "+result);
if (ArrayLibrary.hasDuplicates(nums))
System.out.println("Array has duplicate values");
else
System.out.println("Array values are all unique, no duplicates here");
}
Testing
Consider the following code:
int[] nums ={10,4,50,128,4,-1,49};
What would the following calls to the various methods return? If you can fill in the black in the rightmost column, then you can create test cases to make sure that the code is working correctly.
Call Returns...
ArrayLibrary.findLargest(nums); 128
ArrayLibrary.findLargest(null);
ArrayLibrary.findLargest(new int[0]);
ArrayLibrary.findSmallest(nums);
ArrayLibrary.isContained(nums,10);
ArrayLibrary.isContained(nums,4);
ArrayLibrary.appearsMultipleTimes(nums,4);
ArrayLibrary.appearsMultipleTimes(nums,10);
ArrayLibrary.appearsMultipleTimes(nums,77);
Solution
You have been given two files (ArrayLibrary.java Download ArrayLibrary.javaand ArrayLibraryTest.java Download ArrayLibraryTest.java) that have the beginnings of the code for the project.
Add comments to the code so that you gain full points for Style/Coding.
Complete the code for the methods above (and included in the ArrayLibrary.java Download ArrayLibrary.java).
Write test cases to exercise all lines of code in the methods.
As you add more test cases, you will recharge your submission energy. Submit until you get full points for Style/Coding (45.0/45.0) and get close to full points for Correctness/Testing (45.0/45.0).
Submission Instructions:
1. Only submit your ArrayLibrary.java and ArrayLibraryTest.java files in Web-Cat in a zipped folder.
2. DO NOT INCLUDE PACKAGES IN YOUR FILES.
3. DO NOT SUBMIT OTHER FILES EXCEPT THE TWO REQUIRED FILES.
Reference

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago