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 java method that initializes an array of 10 random numbers integers between 1 and...

    Write a java method that initializes an array of 10 random numbers integers between 1 and 100 and a method that finds the largest odd number in the array of integers please.

  • 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...

  • Create a program that creates an array of 500 random numbers between -10 and 10. Write...

    Create a program that creates an array of 500 random numbers between -10 and 10. Write several functions: Function 1 - prints the array with a certain number of elements per line. Prototype: void printArray(int array[], int numElements, int numPerLine, ostream &os) Function 2 prints only the array elements that are evenly divisible by an input number. Prototype: void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os) Function 3 takes the input array and returns the maximum, the...

  • 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 an application that has an array of at least 20 integers. It should call...

    Java: Write an application that has an array of at least 20 integers. It should call a method that uses the sequential search algorithm to locate one of the values. The method should keep a count of the number of comparisons it makes until it finds the value. Then the program should call another method that uses the binary search algorithm to locate the same value. It should also keep count of the number of comparisons it makes. Display these...

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