Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PO 0 1 Help me fix my code please, I dont want to use any different method types just want to make what I have

PO01 "Help me fix my code please, I dont want to use any different method types just want to make what I have work please. Use jGrasp and its in Java.
import java.util.*;
/**
* The program asks the user for three number inputs(range:(x, y), and size of all 5 random number sets) to determine and display the array's average of the 5 sets of random numbers.
*
* @bugs No bugs in the program, if any.
*/
public class LastnameFirstname {
// main method
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int userInput =0;
int userMin =0;
int userMax =0;
double set[]= new double[userInput];
double sum[][]= new double[userInput][];
// giving user brief instructions
System.out.println(""Aloha! This program simply creates 5 sets of random numbers that;"");
System.out.println(""Will ask you for min and max values then calculates the average of each set."");
System.out.println(""Before we ask you for the min and max."");
for (int i =0; i < userInput; i++){
System.out.println(""How many numbers are in each of these 5 sets? ""+ userInput);
userInput = input.nextInt();
// asking user for range of numbers to generate for each random set
System.out.println(""According to the amount of random numbers in each set chosen by you;"");
System.out.println(""Please provide the following information below:"");
System.out.println(""Enter minimum value: ""+ userMin);
userMin = input.nextInt();
System.out.println(""Enter maximum value: ""+ userMax);
userMax = input.nextInt();
System.out.println(""Okay give me a couple seconds..."");
System.out.println(""..A..L..O..H..A.."");
System.out.println(""Average of all 5 sets:"");
System.out.println(""Set #1: ""+ average(sum));
System.out.println(""Set #2: ""+ average(sum));
System.out.println(""Set #3: ""+ average(sum));
System.out.println(""Set #4: ""+ average(sum));
System.out.println(""Set #5: ""+ average(sum));
}
}
// Generate a double array with given size, minimum, and maximum value
public static double[] generateNums(int userInput, int userMin, int userMax){
Random random = new Random();
double[] data = new double[userInput];
for (int i =0; i < userInput; i++){
data[i]=(Math.random()*(userMax - userMin +1)+ userMin);
}
return data;
}
// method getting the average of each individual sets
public static double average(double[] data){
double sum =0;
for (int i =0; i < userInput; i++){
sum += data[i];
}
return sum / data.length;
}
}"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

analyzing arrays

Answered: 1 week ago