[SOLVED] IT2650 Assignment7-Collections (Arrays, Vectors, Lists)

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment7-f6ry06.zip (858.5 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Collections (Arrays, Vectors, Lists, etc)

The point of this assignment is to cover a few of the basic principles of collections and processing those collections.

The solution for this assignment (at least the one I implemented) can be accomplished by inserting the code to perform a bubble sort on data entered by the user.

Using the IDE

Remember that all code must be submitted in text format.

Initial Code & Output

 

Load the following code into the online compiler:

 

https://www.jdoodle.com/online-java-compiler/

 

Please copy the following code into the IDE, compile and run it.

public class A07 {

 

// logic to sort the elements

public static void bubbleSort(int array[]) {

 

}

 

private static void swap(int i, int j, int[] array) {

int temp;

temp = array[i];   array[i] = array[j];

array[j] = temp;

}

 

private static void printArray(int[] input) {

for (int i = 0; i < input.length; i++) {

System.out.print(input[i] + ” “);

}

}

 

public static void main(String[] args) {

 

int[] input = { 4, 2, 9, 6, 23, 12, 34, 0, 1 };

 

System.out.print(“A07 – written by Matt Weisfeld\n\n”);

System.out.print(“Initial Array:\n”);

printArray(input);         System.out.print(“\n”);

 

System.out.print(“\nIntermediate Steps:”);                               bubbleSort(input);

 

System.out.print(“\n\nSorted Array:\n”);         printArray(input);

}

}

 

This code covers a lot of programming concepts. Please take this opportunity to study the code and determine what is going on.

When you execute the code it will look something like this:

 

Problem

 

Note that the array is not sorted since the bubbleSort method is empty. This is a working application – now I want you to extend it and add some functionality.

 

All you need to do (and this is not trivial) is to add the code to sort arrays inside the following method:

 

public int[] bubble_srt (int array[])

 

Here are the constraints that you must include in your program.

  • Include an output statement at the beginning of the program with the assignment number and your name:

A07 – Written by Matt Weisfeld

  • The sort must be a bubble sort.
  • Print out the initial array (already provided).
  • Identify the number of the current pass (iteration) through the array.
  • Print out the intermediate result of each pass (print routine already provided). 6) End the program when the array is completely sorted.

Note the number of steps will be different depending on the input array and the sort algorithm used.

 

Final Output

 

Once completed, your output (in the following test case) should look like this:

 

    Note the input box is empty

  • Assignment7-f6ry06.zip