menu
bartleby
search
close search
Hit Return to see all results

use javaDevelop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entered into the array. The user will then enter that number of unique integers (negative or positive). Do not allow the number of values entered to exceed the array size.Develop methods to: ‘main’ method.Print the array Sort the array ( YOU MUST DEVELOP YOUR OWN SORT METHOD – don’t use someone else’s)Determine the highest value Determine the lowest valueCalculate the average value (double)

Question

use java

Develop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entered into the array. The user will then enter that number of unique integers (negative or positive). Do not allow the number of values entered to exceed the array size.

Develop methods to: ‘main’ method.

Print the array Sort the array ( YOU MUST DEVELOP YOUR OWN SORT METHOD – don’t use someone else’s)

Determine the highest value Determine the lowest value

Calculate the average value (double)

check_circleAnswer
Step 1

Program plan:

  • Import the required packages.
  • Define a class named “ArraySort”.
    • Define a “main()” method.
      • Declare the required variables.
      • Get the size of an array from the user and store it to the variable.
      • Get the array values from the user.
      • Call “sort()” method to sort the array.
      • Call “getHighest()” method to determine the highest value.
      • Call “getLowest()” method to determine the lowest value.
      • Call “getAvg()” method to determine the average value.
      • Then print statement to print the results.
    • Define a “sort()” method.
      • “for” loop to sort the array values.
    • Define a “getHighest()” method.
      • “for” loop to iterate the sorted array values.
        • “if” statement to check the highest value and return.
      • Define a “getLowest()” method.
        • “for” loop to iterate the sorted array values.
          • “if” statement to check the lowest value and return.
        • Define a “getAvg()” method.
          • “for” loop to iterate the sorted array values and compute the total.
          • Compute and return average of the array values.
Step 2

Program:


// Import the required packages
import java.util.Scanner;

// Definition of ArraySort class
public class ArraySort {

// Definition of main() method
public static void main(String[] args) {

// Declaration of requird variables
int highestVal, lowestVal;
double avg;

// Creation of object for scanner
Scanner scan = new Scanner(System.in);

// Get the size of an array from the user
System.out.print("Enter the size of an array:");

// Store the size in arrSz
int arrSz = scan.nextInt();

// Array creation
int[] arr = new int[arrSz];

// for loop to iterate and get the integer from the user
for (int count = 0; count < arr.length; count++) {

// Print statement
System.out.print("Enter an integer: ");

// Store the integers to the array
arr[count] = scan.nextInt();
}

// Call sort() method to Sort the array
sort(arr);

// Call getHighest() method to determine the highest value
highestVal = getHighest(arr);

// Call getLowest() method to determine the lowest value
lowestVal = getLowest(arr);

// Call getAvg() method to determine the avg value
avg = getAvg(arr);

// Print statement
System.out.println("The sorted array values are: ");

// for loop to iterate and print the sorted array values
for (int count = 0; count < arr.length; count++) {

// Print the array
System.out.println(arr[count]);
}

// Print the highest value
System.out.println("The highest value in the array is: " + highestVal);

// Print the lowest value
System.out.println("The lowest value in the array is: " + lowestVal);

// Print the average of the array values
System.out.println("The average of the array values is: " + avg);

}

// Defintion of sort() method
public static void sort(int[] arr) {

// Declare an integer variable temp
int temp;

/* for loop to iterate the loop and index 1 is
compared to the array length and incremented */
for (int indx1 = 0; indx1 < arr.length; indx1++) {

/* for loop to iterate the loop and index 2 is
compared to the array length and incremented */
for (int indx2 = indx1 + 1; indx2 < arr.length; indx2++) {

// If the first number is greater than the second,
// the two numbers switch indx positions. We store
// the second number first so it's not overwritten.
//-------------------------------------------------

// Check f...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Prove that the following languages are not regular: (b) L = {anblak : k ≠ n + l}.

A: First, assume the given language is regular.Then apply pumping lemma to prove the statement is not r...

question_answer

Q: Construct Turing machines that will accept the following languages on {a, b}: L = L (aaba*b).

A: Turing machine: Turing machine is a model of a hypothetical computing machine which can use a predef...

question_answer

Q: 4.23 (Financial application: payroll) Write a program that reads the following information and print...

A: C code#include&lt;stdio.h&gt;#include&lt;string.h&gt; int main(){char employeeName[20]="";double hou...

question_answer

Q: List the octal and hexadecimal numbers from 1410 to 3210. Using A and B for the last two digits, lis...

A: Answer:Listing octal values from 1410 to 3210:Divide 14 by 8 (octal number) giving 1 remainder 61 is...

question_answer

Q: How to write a function in python that takes a string s = kkeeepinng and returns the non-repeating c...

A: Program plan:Inside the function, create two empty list named “dup_list[]” and “non_dup_list[]”.Use ...

question_answer

Q: define virtual memory

A: Virtual memory, in context with computing, is memory management technique that is used by the operat...

question_answer

Q: do big data could replace the artistic vision of a creative director? and why?

A: Justification:“Yes”, big data replace the artistic vision of a creative director.

question_answer

Q: Write a complete C++ program that does the following:1. Create a 2-dimensional array with 8 rows and...

A: 1)Program plan:Declare the variables “rows” and “cols” as integerAssign “rows” to “8” and “cols” to ...

question_answer

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: The program in Java would be using print and printf statements with formatting for left alignment of...

Sorry about that. What wasn’t helpful?