My goal is to have it output the min max avg and a barchart.
`
package arraystuff1;
import java.util.Random;
public class problem1
{
public static void main(String[] args)
{
int min=0;
int max=0;
int avg=0;
//initialize array
Random randomNumbers = new Random();
final int Length = 30;
int[] array1 = new int[Length];
for ( int counter = 0; counter < array1.length; counter++ )
{
array1[ counter ] = 1+randomNumbers.nextInt( 100 );
}
//array tested and produces correct output
for ( int counter = 0; counter < array1.length; counter++ )//minimum
{
min = functionsp1.min(array1[counter],min);
if(counter == Length-1)
System.out.printf("The minimum value is: %d\n",min);
}
for ( int counter = 0; counter < array1.length; counter++ )//maximum
{
max = functionsp1.max(array1[counter],max);
if(counter == Length-1)
System.out.printf("The maximum value is: %d\n",max);
}
for ( int counter = 0; counter < array1.length; counter++ )//average
{
avg = functionsp1.avg(array1[counter],Length);
if(counter == Length-1)
System.out.printf("The average value is: %d\n",avg);
}
for ( int counter = 0; counter < array1.length; counter++ )//average
{
functionsp1.bar(array1[counter],Length);//print a line showing range of the bar graph use switch case to build frequencies for each 10th unit
functionsp1.freq(array1[counter],Length);//print stars representing number of random numbers that fit in this category
}
}
}
` ///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
`
package arraystuff1;
public class functionsp1
{
public static int min(int counter,int min)//input array index and length
{
if (counter < min)
{
counter = min;
}
return counter;
}
public static int max(int counter,int max)
{
if (counter > max)
{
counter = max;
}
return counter;
}
public static int avg(int current,int total)//input array length for total and index for current
{
int sum;
int fintotal;
for (int counter = 0; counter < total; counter++ )
{
sum = current + sum; // random number 0-99 add 1 to make it 1-100
if (counter == total)
fintotal = sum/total;
return fintotal;
}
System.out.printf("The average of the array is: %2d",fintotal);
//System.out.printf( "%s%8s\n", "Index", "Value" ); // column headings
return fintotal;
}
public static void bar(int index,int limit)//length and array variable
{
System.out.println("Grade Distribution: ");
for(int counter = 0; counter < limit;counter++)
{
if (counter ==10)
System.out.printf("%5d: ", 100);
else
System.out.printf("%02d-%02d: ",counter*10,counter*10+9);
}
}
public static void freq( int stars )
{
for(int counter=0;counter<stars ; counter ++)
System.out.print("*");
} // end main
}
`
I have verified the array initialized with 30 random numbers in the range of 1-100. My goal is to get the bar chart and the other functions to work but this is the first time I have played with an array any suggestions?
Let your Functionsp1 class methods deal with the Array for example:
I still can't figure out what the
freq()method is suppose to accomplish.As the code above stands right now, if run will produce something like the following in the Console Window: