Question

Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1...

Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1 - 100) and returns the maximum number, minimum number, average of all numbers, and prints a Bar Chart to show the number distribution (1-9, 10-19,20-29, …80-89, 90-100). Note; maximum number, minimum number, average number, and the Bar Chart must use implemented as separate methods in a separate class. Method call should pass an array as an argument. Methods should accept an array as an input parameter, but return a number (double or integer). The bar chart will be in asterisk form. Sample output:

Maximum number: 96

Minimum number: 3

Average: 54

Bar Chart:

1-9: ****

10-19: ******

etc.

Also include the UML activity and class diagrams.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

class ArrayOperations{
// for maximum
public static int maximum(int a[])
{
int max = a[0];
for(int i=1; i<a.length;i++)
{
if(max < a[i])
max = a[i];
}
return max;
}
  
// for minimum
public static int minimum(int a[])
{
int min = a[0];
for(int i=1; i<a.length;i++)
{
if(min > a[i])
min = a[i];
}
return min;
}
  
// for bar chart
public static void barChart(int a[])
{
System.out.println("\nBar Chart:");
  
// storing frequency first
int[] freq = new int[10];
for(int i=0; i<a.length;i++)
{
if(a[i] == 100)
freq[9]++;
else
freq[a[i]/10]++;
}
  
// using that frequency printing chart
int x = 1, y = 9;
for(int i=0; i<freq.length;i++)
{
if(i==9)
y = 100;
System.out.printf("%2d-%3d : ",x,y);
for(int j=0; j<freq[i]; j++)
{
System.out.print("*");
}
x = x + 10;
y = y + 10;
  
if(i==9)
y = 100;
System.out.println();
}
}
  
}
class Main {
public static void main(String[] args) {
  
int[] a = new int[100];
Random r = new Random();
  
for(int i=0; i<100; i++)
{
a[i] = r.nextInt(100) + 1;
}
  
System.out.println("Maximum number: "+ArrayOperations.maximum(a));
System.out.println("Minimum number: "+ArrayOperations.minimum(a));
ArrayOperations.barChart(a);
}
}

Maximum number: 1060 Minimum number: 3 Bar Chart: 1- 9 21- 29 31- 39 81- 89 91-100:

Add a comment
Know the answer?
Add Answer to:
Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • Write a JAVA program with methods that initializes an array with 20 random integers between 1...

    Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...

  • LAB: How many negative numbers Write a program that generates a list of integers, and outputs...

    LAB: How many negative numbers Write a program that generates a list of integers, and outputs those integers, and then prints the number of negative elements. Create a method (static void fillArray(int [] array)) that uses Random to generate 50 values (Random.nextInt()), put each value in the array (make sure to pass the array in to this method as an argument). Write another method (static int printAndCountNeg(int [] array)) that prints each element’s value and count the number of negative...

  • 1. Write a C code that do the following: Generate array of random integer numbers of...

    1. Write a C code that do the following: Generate array of random integer numbers of size 25 Fill the array with random integers ranging from [1-100] Find the maximum number of the array and its location Find the minimum number of the array and its location Search for a number in the array Print the array Flip the array Sort this array Quit the program when the user choose to exit

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

    (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...

  • Write a Java program, In this project, you are going to build a max-heap using array...

    Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...

  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT