Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 5: Utility Methods This assignment will be building on to the prior assignment and will utilize the same Eclipse project. Please refer to assignment

Assignment 5: Utility Methods

This assignment will be building on to the prior assignment and will utilize the same Eclipse project. Please refer to assignment 3 if you need assistance downloading the project template and understanding the existing architecture that you will contribute to.

Please code this in Java using Eclipse.

For this assignment we'll be creating a new class called, Utilities. The Utilities class will contain two methods; removeDuplicates and linearSearch.

Task 1 - Utilities

Package: edu.institution.actions.asn5

Class: Utilities

Create a class called Utilities and create these two methods.

public class Utilities {

public void removeDuplicates(List items){

}

public E linearSearch(List list, E key){

return null;

}

}

Method: removeDuplicates

public void removeDuplicates(List items)

This method excepts a list of items and removes the duplicates from the list. After this method completes, the supplied list should not contain any duplicate items.

For example:

List numbers = new ArrayList<>();

numbers.add("one");

numbers.add("two");

numbers.add("one");

Utilities utilities = new Utilities();

utilities.removeDuplicates(numbers);

// the numbers list should contain two records; "one" and "two"

List numbers = new ArrayList<>();

numbers.add(1);

numbers.add(1);

numbers.add(1);

Utilities utilities = new Utilities();

utilities.removeDuplicates(numbers);

// the numbers list should contain one record; 1.

Method: linearSearch

public E linearSearch(List list, E key)

Implement a generic method to do a linear search. Your linear search method should accept a list containing a generic type and a key record to search for in the generic list. Your linear search should return the record associated with the supplied key or null if the key does not exist in the supplied list.

JUnit Tests

Write enough JUnit tests to achieve 100% test coverage and think carefully about your tests. At a minimum, you need to include a unit test that uses an array of Integers, an array of Strings, and an array of LinkedInUser's. You should also test any unusual cases you can think of: What if the ArrayList is empty?

What if it contains only one item?

What if your removeDuplicates method is passed an ArrayList in which every item is identical?

What if the arguments to the two methods are null?

And so on.

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions