anonymous
  • anonymous
Hello! I Need help writing a small java program... This is what it's suppose to do 1. Write a program RandomArrayAnalyzer to randomly generate 20 numbers between 0 and 100 (inclusive), then print out the 20 numbers as follows: 20 | 15 | 5|…… Then print the sum of the 20 numbers, average , minimum and maximum number.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
so far i have this /** * Generates 20 random numbers and then returns average and maximum values. */ public class RandomDataAnalyzer { public static void main(String [] args) { // Creates constructor and sets value to 1000. DataSet numbers = new DataSet(100); // Creates loop and increaments number generated by one until there are 100 generated between 0 and 1000. final int count = 20; for(int i = 1; i <= count; i++) { // Generates random numbers. int randomize = numbers.generate(); // Displays all random numbers generated. System.out.println(randomize + " "); // Adds all numbers. numbers.add(randomize); } // Prints average. System.out.print("The average is: " + numbers.getAverage()); // Prints maximum value from the 100 random generated numbers. System.out.println("The maximum is: " + numbers.getMaximum()); } }
anonymous
  • anonymous
I need to change this so it will use arrays instead.
anonymous
  • anonymous
how can i print the sum of the random numbers being generated? numbers.add(randomize);

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

eSpeX
  • eSpeX
Why not just print with a System.out.println("Your random sum: " + randomize); statement?
anonymous
  • anonymous
I tried that but got this error System.out.println("Your random sum: " + randomize); Error: /Users/lalo/Dropbox/Notebook/ITEC 2120 - INTRO TO JAVA/PROJECTS/8/RandomDataAnalyzer.java:36: cannot find symbol symbol : variable randomize location: class RandomDataAnalyzer
anonymous
  • anonymous
I think problem might be in my class public int add(int x) { sum = sum + x; if (count == 100 || maximum < x) maximum = x; count++; return (x); }
eSpeX
  • eSpeX
Troubleshooting your problem is going to be difficult without the entirety of your code. If you are calling your randomize variable from outside a class that does not have access to the variable, then it will not be able to find said variable. It also appears that you are declaring your randomize variable from within your 'for' loop, and re-declaring it with each pass. This variable will not have scope outside of the loop, so while you are within the loop you are able to print its value because you have local access to it but outside randomize no longer exists.
anonymous
  • anonymous
import java.util.Random; public class DataSet { private double x; private double sum; private double count; private double average; private double maximum; private Random generator; public DataSet(int randomnum) { // initialise instance variables x = randomnum; generator = new Random(); } /** Adds values. @return int x value randomly generated. If statement sets maximum value when x is less than max. */ public void add(int x) { sum = sum + x; if (count == 100 || maximum < x) maximum = x; count++; } /** @return Maximum value. */ public double getMaximum() { return maximum; } /** Calculate average from all 100 numbers generated. @return average value. */ public double getAverage() { average = (sum/100); return average; } public int generate() { return 1 + generator.nextInt((int)x); } }
anonymous
  • anonymous
/** * Generates 20 random numbers and then returns average and maximum values. */ public class RandomDataAnalyzer { public static void main(String [] args) { // Creates constructor and sets value to 100. DataSet numbers = new DataSet(100); // Creates loop and increaments number generated by one until there are 20 generated numbers between 0 and 100. final int count = 20; for(int i = 1; i <= count; i++) { if (i>0) { System.out.print(" | "); } // Generates random numbers. int randomize = numbers.generate(); // Displays all random numbers generated. System.out.print(numbers.generate()); // Adds all numbers. numbers.add(randomize); } // Prints sum. System.out.println("sum" + randomize); // Prints average. System.out.println("The average is: " + numbers.getAverage()); // Prints maximum value from the 100 random generated numbers. System.out.println("The maximum is: " + numbers.getMaximum()); } }
anonymous
  • anonymous
That's all I have. I just need to get the sum to print out now.
anonymous
  • anonymous
int randomize is out of scope when you're attempting to print its value.

Looking for something else?

Not the answer you are looking for? Search for more explanations.