Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

221-dt-content-rid-1 782399-1/courses/85763/os2 14exam04h%281%29.pdf College of

ID: 3909900 • Letter: 2

Question

221-dt-content-rid-1 782399-1/courses/85763/os2 14exam04h%281%29.pdf College of Business and Technology, Morehead State University Exam 4 CS 214 Introduction to Programming-Java, Summer 2018 Create a lava console program that satisfies the fo 1. The program prompts a user to enter a number. The program uses the input value to create an array 2. The program asks the user to enter a series of numbers, and the numbers are to be entered and stored 3. The program asks the user to select the way of how the numbers are sorted, i.e, ascending or with the number of elements based on the first input value. in the array descending. If the user enters a, the numbers are sorted in ascending order (and displayed). If the user enters d, the numbers are sorted in descending order (and displayed) The program asks the user whether he/she wants to continue. If the user enters c or C, the program continues and repeats the process again. If the user enters any other key, the program stops 4. C:CIS214>java Exam04TomJones Enter a positive integer3 Enter item 1: 4 Enter item 2: Enter iten 3 You have entered 427 Bow to display the numbers? Entera for ascending, or d for deacending: a The nunbers in ascending order To continue, enter e; to quit, enter any other key Enter a positive integeri 4 Enter aten 1: Enter iten 2 Enter iten 3 Enter item 4 You hav? entered 7 6 39 How to display the nunbe:s? Knter a for ascending, ox d for descending: sd The nmbere in descending order 763 To continus, enter oi to quit, anter sny other kay CiVCIS214 Your code should follow the following requirement 1. Do not use Java's default methods to sort numbers. You must create your own methods to sort numbers in a separate class Use the default package. Do not create your own packages The algorithms for sorting numbers should be managed in methods af a separate class (eg NumberSort). Do not place the methods in the class that has a mainl) method 2. 3. DELL

Explanation / Answer

The program in given question requires knowledge of creating our own methods to sort the numbers in the array.

Now, sorting numbers in java is easy because the Arrays class allow us to do everything with us. Arrays is part of java,util group of classes, but we will create our own method here.

method() in java is equivalent to functions in C++, and is essentially a group of statements written together to perform a specific task.

So, let us call our method Sorter.

step 1: Create a method

As you might be familiar with, public static is a modifier, int is the datatype of method, and Sorter is the name of method. a, b,c are the arguments that the method will deal with.

Now comes our code-

public static int Sorter(int a, int b, int c)
{

int a = Integer.parseInt(int);
int b = Integer.parseInt(int);
int c = Integer.parseInt(int);

if ((a > b && a > c))
{
if(b > c)
{
ArrayFill(a,b,c);
//arrayfill is another method we have used to fill numbers in the array.
}
else
ArrayFill(b,c,a);
}
else if ((b > a && b > c))
{
if(a > c)
{
ArrayFill(c,b,a);
}
else
{
ArrayFill(a,c,b);
}
}
else if ((c > a && c > b))
{
if(a > b)
{
ArrayFill(b,a,c);
}
else
ArrayFill(a,b,c);
}
else
{
System.out.println("ERROR!");
}

}

public static int ArrayFill(int, int, int){
int num=0;
int array[] = new int [2];
for ( array[a]=1; array[a]<=array.length; array[a]++){
System.out.println(array[a]);
}

Now, you will need two classes to build your project.

1. Main() class, where you will prompt the user to input three numbers, and display the output.

2. Sorter class (saved as sorter.java and containing the above code for Sorter() and ArrayFill()).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote