Answered step by step
Verified Expert Solution
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 rd am: The two source files linked below ArrayLibraryjava and ArrayLibraryTest.java were wrong. Please download them again.
You just submit your code to WebCAT to be graded.
Learning objective:
gain practice with JUnit test cases
gain familiarity with CCI Style Guide
write code using arrays
Project
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 elements.
The methods you must implement are:
int findLargestint nums
returns the index to the largest number in nums or if the array is either empty or null
int findSmallestint nums
returns the index to the smallest number in nums or if the array is either empty or null
boolean isContainedint 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 appearsMultipleTimesint 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 hasDuplicatesint nums
returns true if the array nums contains at least one element that appears more than once in the array ie there is a duplicate Should return false otherwise or if the array is either empty or null
int sumAllint nums
returns the sum of all values in the nums array. Should return if the array is either empty or null
double averageint nums
returns the sum of all numbers in the array divided by the number of elements in the array ie the average Should return Double.NaN not a number if the array is null or has elements in which case you can't divide by
Example of how to use ArrayLibrary
Driver method, use to make sure things compile.
public static void mainString args
int nums ;
int result;
result ArrayLibrary.findLargestnums;
System.out.printlnLargest value is result;
if ArrayLibraryhasDuplicatesnums
System.out.printlnArray has duplicate values";
else
System.out.printlnArray values are all unique, no duplicates here";
Testing
Consider the following code:
int nums ;
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.findLargestnums;
ArrayLibrary.findLargestnull;
ArrayLibrary.findLargestnew int;
ArrayLibrary.findSmallestnums;
ArrayLibrary.isContainednums;
ArrayLibrary.isContainednums;
ArrayLibrary.appearsMultipleTimesnums;
ArrayLibrary.appearsMultipleTimesnums;
ArrayLibrary.appearsMultipleTimesnums;
Solution
You have been given two files ArrayLibraryjava 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 StyleCoding
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 StyleCoding and get close to full points for CorrectnessTesting
Submission Instructions:
Only submit your ArrayLibrary.java and ArrayLibraryTest.java files in WebCat in a zipped folder.
DO NOT INCLUDE PACKAGES IN YOUR FILES.
DO NOT SUBMIT OTHER FILES EXCEPT THE TWO REQUIRED FILES.
Reference
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started