Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***This is my second time asking this question. Last expert answered it as an explanation but I couldn't see the steps. So please answer it

***This is my second time asking this question. Last expert answered it as an explanation but I couldn't see the steps. So please answer it in regular form not explanation. ***

I need help with my assignment. I have got the random integer code set up to work but I can't seem to get the array sort to work. I have included my assignment directions and my code.

Assignment Description and Requirements:

Create an Intellij application that fills an array with 1,000 random integer elements, each integer element array must be between the values of 1 and 10. Students can use the Random Class or the random method of the Math class to generate the random numbers. Using the Bubble Sort Algorithm, Your Program should sort the numbers in the Array and Print the results. The program should first print the unsorted version of the array. After printing the unsorted array of 1000 Integers, the program should print the sorted version of the array. When printing both the sorted and unsorted versions of the array, each element should be delimited by a line feed. After printing both versions of the array, your program should then iterate through the array summing and averaging the elements in the array Finally, your program should also print the average and sum of the values in the array. You Program cannot use predefined Classes or methods in Java that perform frequency counts such as ArrayList, HashMap, Set, or Map and their associated methods. Students must design and develop their own algorithms to solve the problem. Your application should output a neatly formatted summary report to a text file with the summary results, not the entire array. Your program should exhibit good modular development. The Use of the Array class object or the ArrayList class object is also not permitted

Here is a copy of my code:

public class Main { public static void main(String[] args) { //initialize my array int[] array = new int[1000]; int i; // the for loop to generate the 1000 random numbers between 1 and 10 for (i = 0; i < 1000; i++) { array[i] = 1 + (int) (Math.random() * 10); } //for loop to print out the unsorted array list. for (i = 0; i < array.length; i++) { System.out.println(array[i]); } System.out.print("This is the unsorted array list elements."); // the start of the code that contains the sorting of the array boolean swapped; int j,temp; // do { swapped= false; for (i = 0; i < array.length - 1; i++) { for (j = 0; j < array.length - 1; j++) { if (array[j] < array[j + 1]) { temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; swapped = true; } } } }while (swapped) ; System.out.println(array[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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions