I need some serious help. - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# I need some serious help.

Posts: 2Member
I am in a Computer Programming class at school and I was out sick all last week and we got this assignment and I am totally lost because I was not there for the lessons. I am not asking you to code this for me I am asking how I would go about this. The first one involves methods, which I don't get at all..

This is the first part, how would I be able to do this at all? I am not asking you to code this just give me some insite. We are using [url=http://compsci.ca/holtsoft/Turing 4.1.1.zip]Java Ready To Program IDE[/url] and its HSA template for coding.
[spoiler]

i) public static void singHappyBirthday (String name)
ii) public static int daysToHours (int days)
iii) public static int cube (int number)
iv) public static int largest (int num1, int num2, int num3)
v) Write a method called convertToGrade
vi) Write a method called roundNumber
[/spoiler]

The second part I am lost on is this
[spoiler]a) Write a program to fill an array with 50 random integer elements. The random values should be between -100 and 100 inclusive.

b) In a separate loop, loop through the array to find and print the max number, the min number, and the average of all numbers.
[/spoiler]

I have the first part I think

[code]

// The "Q4" class.
import java.awt.*;
import hsa.Console;

public class Q4
{
static Console c; // The output console

public static void main (String[] args)
{
c = new Console ();
int[] randomArray;

randomArray = new int [50];
int max = -101

for (int count = 0 ; count < randomArray.length ; count++)
{
randomArray [count] = (int) (Math.random () * 200) - 100;
}

} // main method
} // Q4 class
[/code]

But I have no idea how to do the second part. Any help at all will be very helpful and I am completely lost.

• Posts: 55Member

a) Write a program to fill an array with 50 random integer elements. The random values should be between -100 and 100 inclusive.
Check Random number generator tut

Declare a counter, `int count=0;`(declare the counter before the whole Do...WHILE loop)

randNo=(use the function to generate a random number).
Put a condition `if(randNo>=-100 && randNo<=100) {add it to the array; count++;}`
DO this WHILE count<=50
(randNo is the random generated number)

b) In a separate loop, loop through the array to find and print the max number, the min number, and the average of all numbers.
`max=array_name[position_0];`
Loop over the array(from position 1 to the last element) and compare each element with max. If one of them is greater then the actual max, make `max=array_name[position_i];`
Same for min.

Average: `int sum=0; double avg=0;`Loop over the array and add each element to sum. `avg=sum/array_length;`

I recommend you this tutorial for learning methods. That channel has also get and set methods, static methods.