Purchase Solution

Java class creates an array of integers

Not what you're looking for?

Ask Custom Question

Java Programming - Array Sort

Description

Write a Java class that creates an array of integers, fills it with values, prints the unsorted values, sorts the values into ascending order, and finally prints the sorted values.
Write a class named ArraySort that has no instance variables, and the following public static methods
public static void main(String[] args) - this main method performs the following steps:
? Prompts for the size of the array to be created (limit it to between 3 and 10).
? Creates a Scanner to read the int value for the array size, reads it, and verifies it is within the correct range.
? Dynamically creates a local integer array of the requested size.
? Calls the fillArray method to read values into the array (passing its local array as the parameter).
? Calls the printArray method to print the unsorted values.
? Calls the sortArray method to sort the array values into ascending order.
? Calls the printArray method to print the sorted values
public static void fillArray(int[] array) - this method fills the parameter array with values. It creates a local Scanner object, loops once for each array element, prompts for a value, reads an integer value using the Scanner, and assigns it to the array element.
public static void printArray(int[] array) - this method prints all the values in the parameter array.
public static void sortArray(int[] array) - this method sorts the values in the parameter array into ascending order. You must write the Java code to do the actual sorting of the array values (see example logic below).
Sample Output
Enter the size of the array (3 to 10):
3
Enter 3 values
Enter value for element 0:
15
Enter value for element 1:
10
Enter value for element 2:
5
The unsorted values...
15
10
5
The sorted values...
5
10
15
Done - press enter key to end program
Test Data
Use the following test data, plus an example of your own:
1000, -200, 500, 150, 600, 800, 150, 50, -25

Purchase this Solution

Solution Summary

The Java class creates an array of integers. The program fills its values and prints the unsorted values.

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Javscript Basics

Quiz on basics of javascript programming language.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.