Question

I need some help doing this Java project. 1.Implement the MySort class with the following operations....

I need some help doing this Java project.

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 binarySearch, and print out the returned value onto screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

public class MySort{
public static void bubbleSort(MyArrayList arraylist)
{
int n = arraylist.size();
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arraylist[j] > arraylist[j+1])
{
// swap temp and arr[i]
int temp = arraylist[j];
arraylist[j] = arraylist[j+1];
arraylist[j+1] = temp;
}
}
public static void selectionSort(MyArrayList arraylist)
{
int n = arraylist.size();
  
// One by one move boundary of unsorted subarray
for (int i = 0; i < n-1; i++)
{
// Find the minimum element in unsorted array
int min_idx = i;
for (int j = i+1; j < n; j++)
if (arraylist[j] < arraylist[min_idx])
min_idx = j;
  
// Swap the found minimum element with the first
// element
int temp = arraylist[min_idx];
arraylist[min_idx] = arraylist[i];
arraylist[i] = temp;
}
}


}

Note: According to Chegg's policy we are only allowed to answer first part if there are many. So, I request you to post other part as separate posts

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I need some help doing this Java project. 1.Implement the MySort class with the following operations....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on)...

    I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on) with comments: import java.util.ArrayList; public class Mergesort { /** * Sorts list given using the mergesort algorithm * @param list the list to be sorted * @param first the index of the first element of the list to be sorted * @param last the index of the last element of the list to be sorted */ public static void mergesort(ArrayList<Comparable> list, int first, int...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • Need a help with this one FoodListInterface.java specifies a Java interface for an ADT that maintains...

    Need a help with this one FoodListInterface.java specifies a Java interface for an ADT that maintains a list of foods, dishes or meals. This interface includes two operations: add(String food) – add the name of a food, dish or meal to the list onTheMenu(String food) – check if a given food item is on the list Develop three implementations of this interface, each with a different underlying data structure: Array Linked list ArrayList from the java.util package (a Java Collections...

  • java Create the following classes: DatabaseType: an interface that contains one method 1. Comparator getComparatorByTrait(String trait)...

    java Create the following classes: DatabaseType: an interface that contains one method 1. Comparator getComparatorByTrait(String trait) where Comparator is an interface in java.util. Database: a class that limits the types it can store to DatabaseTypes. The database will store the data in nodes, just like a linked list. The database will also let the user create an index for the database. An index is a sorted array (or in our case, a sorted ArrayList) of the data so that searches...

  • I need help with this java project and please follow the instruction below. thank Class Project...

    I need help with this java project and please follow the instruction below. thank Class Project - Parking Ticket simulator Design a set of classes that work together to simulate a police officer issuing a parking ticket. Design the following classes: •           The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. •          ...

  • ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes,...

    ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie. 1.) The superclass Media will implement Comparable, and will define...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title.   Create a use a menu that contains the following items, and calls corresponding methods...

    in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title.   Create a use a menu that contains the following items, and calls corresponding methods that do the tasks the menu describes. Use classes when they're appropriate. Keep the driver class as simple as possible. Give each class, method and property simple, descriptive names using Hungarian notation. Square a number Simply pass a decimal-type number to the object that does this task. Process its...

  • Need Help! Please Solve using JAVA! TopResult Task: There are a number of situations in which we ...

    Need Help! Please Solve using JAVA! TopResult Task: There are a number of situations in which we want to keep track of the highest value we've seen so far - a highest score, a most recent entry, a name which is closest to the end (or the front) of a list, etc. We can imagine writing a simple class which will do this: a class which will let us enter new results one by one, and at any point will...

  • need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class si...

    need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT