Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program is mostly using the myArrayLIst and the code is a below the directions. 1.Implement the MySort class with the following operations. a.bubbleSort(MyArrayList arraylist)

The program is mostly using the myArrayLIst and the code is a below the directions.

1.Implement the MySort class with the following operations. a.bubbleSort(MyArrayList arraylist) conduct bubble sort on the elements contained in a MyArrayList object. b.selectionSort(MyArrayList arraylist) conduct selection sort on the elements contained in a MyArrayList object.

2.Implement the MySearch class with the following operations. a.binarySearch(MyArrayList arraylist, Comparable target) conduct binary search on sorted elements contained in a MyArrayList object. b.linearSearchSorted (MyArrayList arraylist, Comparable target) conduct linear search on sorted elements contained in a MyArrayList object.

3.Both the MySearch and MySort classes should be created in the collection package.

4.After implementing the MySearch and MySort classes you will test them. To test the MySearch and MySort classes you will create a Lab3 class under the lab package.

5.In the Lab3 class you will create an static void test() method. In this test method you will do the following:

a.Create a numArraylist of MyArrayList type.

b.Generate a sequence of 800 integer numbers in the range [100, 999] using java.util.Random with current system time as the random seed (use java.lang.System.nanoTime()). Insert this sequence of numbers into numArraylistone by one when it is being generated.

c.Sort numArraylist using bubbleSort.

d.Print out numArraylist onto the screen.

e.Prompt user to type in a number through keyboard.

f.Search that number using linearSearchSorted, and print out the returned value onto screen.

g.Call numArraylist.removeRange(50, 650).

h.Then call numArraylist.reverse().

i.Sort numArraylist using selectionSort.

j.Print out numArraylist onto the screen.

k.Prompt user to type in a number through keyboard.

l.Search that number using binary. Search, and print out the returned value onto screen.

The code for the myArrayList

package collection;

/* * @This program clones an array * @author jgemerick0 * @version 2020.20.2 */

public class MyArrayList implements Cloneable{ public Object[] obj; public int maxsize = 100,initialsize = 0; public MyArrayList(){ obj = new Object[maxsize]; } public void append(Object element){ if(initialsize < maxsize) obj[initialsize++] = element; else System.out.println("Full"); } public void clear(){ obj = new Object[maxsize]; } public void contains(Object element){ int flag = 1; for(int i=0;iindex;i--){ obj[i] = obj[i-1]; } obj[index] = element; } public boolean isEmpty(){ if(initialsize == 0) return true; return false; } public void removedAt(int index){ for(int i=index;i= minCapacity) return true; return false; } public Object clone() throws CloneNotSupportedException{ return super.clone(); } public void removeRange(int fromIndex,int toIndex){ for(int i=fromIndex;i

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

how to do a cash budget for a bake sale?

Answered: 1 week ago