A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 3 years ago
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.
anonymous
 3 years ago
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.

This Question is Closed

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0so 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
 3 years ago
Best ResponseYou've already chosen the best response.0I need to change this so it will use arrays instead.

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0how can i print the sum of the random numbers being generated? numbers.add(randomize);

eSpeX
 3 years ago
Best ResponseYou've already chosen the best response.0Why not just print with a System.out.println("Your random sum: " + randomize); statement?

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0I 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
 3 years ago
Best ResponseYou've already chosen the best response.0I 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
 3 years ago
Best ResponseYou've already chosen the best response.0Troubleshooting 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 redeclaring 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
 3 years ago
Best ResponseYou've already chosen the best response.0import 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
 3 years ago
Best ResponseYou've already chosen the best response.0/** * 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
 3 years ago
Best ResponseYou've already chosen the best response.0That's all I have. I just need to get the sum to print out now.

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0int randomize is out of scope when you're attempting to print its value.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.