Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help with this assignment, i feel like im on the right path but my code might be wrong. This is in Java.

Hello, I need help with this assignment, i feel like im on the right path but my code might be wrong. This is in Java. Thank you and will give 5 stars!!

LAB INFO

In this assignment we are going to implement the insertion sort and selection sort program for big integers. The primitive data types in Java only allow you to use at most 64 bits to represent integers, however the inbuilt BigInteger class can be used to define immutable arbitrary-precision integers. Any integer number which is outside of the 64-bit representation may be stored in a BigInteger object if the memory is sufficient.

You are required to learn at least the following operations:

Creating a BigInteger object of a given integer number. (BigInteger constructor)

Creating a random BigInteger object. (BigInteger constructor)

Comparing the values of two BigInteger objects.

Displaying the value of a BigInteger object.

You are allowed to use auxiliary methods in your implementation.

complete the following method which reorganizes the big integers in the given array in ascending order using insertion sort.

public static void insertionSort(BigInteger[] nums)

{

// your program

}

complete the following method which reorganizes the big integers in the given array in ascending order using selection sort.

public static void selectionSort(BigInteger[] nums)

{

// your program

}

write a main method (in the same class) to perform the following tests on your new methods. Creating an array of 10 big integers which are 8-bit and randomly generated. Displaying the content of the array. Sorting the numbers using insertion sort. Displaying the content of the array. Performing the above steps again using selection sort.

/////////MY CODE//////////////////

public static void main(String[] args) { BigInteger[] nums = new BigInteger[10];

for(int i = 0; i < 10; i++){ nums[i] = BigInteger.probablePrime(8, new Random()); }

System.out.println("Unsorted: "); for(int i = 0; i < 10; i++){ System.out.print(nums[i] + " "); } System.out.println();

insertionSort(nums);

System.out.println("Insertion Sort: "); for(int i = 0; i < 10; i++){ System.out.print(nums[i] + " "); } System.out.println();

selectionSort(nums);

System.out.println("Selection Sort: "); for(int i = 0; i < 10; i++){ System.out.print(nums[i] + " "); } System.out.println(); }

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

Students also viewed these Databases questions

Question

=+ 2. How well known are his/her credentials to the audience?

Answered: 1 week ago

Question

what devices typically use SATA cables

Answered: 1 week ago

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago