You are viewing our Forum Archives. To view or take place in current topics click here.
[JAVA]Need some serious help
Posted:
[JAVA]Need some serious helpPosted:
Status: Offline
Joined: Jan 04, 201113Year Member
Posts: 157
Reputation Power: 6
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 [ Register or Signin to view external links. ] and its HSA template for coding.
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
The second part I am lost on is this
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.
I have the first part I think
But I have no idea how to do the second part. Any help at all will be very helpful and I am completely lost.
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 [ Register or Signin to view external links. ] and its HSA template for coding.
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
The second part I am lost on is this
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.
I have the first part I think
// 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
But I have no idea how to do the second part. Any help at all will be very helpful and I am completely lost.
#2. Posted:
Status: Offline
Joined: May 30, 201014Year Member
Posts: 438
Reputation Power: 49
Status: Offline
Joined: May 30, 201014Year Member
Posts: 438
Reputation Power: 49
For your methods as an example:
So i to iv give you a method prototype where the return value and attributes/parameters are already stated.
v and vi are the same thing except they haven't provided you with the prototype. As an example the method prototype for "convertToGrade" may look like this:
I think you're random array is okay, you would just need another for loop which loops over the size of the array. You would also need to have 3 variables; min, max and sum. So in your for loop you could check if the current number is less than min, if it is, set min as the new number and continue. Always add to the sum so an average can be found doing sum/arraySize.
public static void singHappyBirthday (String name){
System.out.println("Happy Birthday to You.");
System.out.println("Happy Birthday to You.");
System.out.println("Happy Birthday dear" + name + ".");
System.out.println("Happy Birthday to You.");
//This will probably be different for your HSA thing you're using.
}
So i to iv give you a method prototype where the return value and attributes/parameters are already stated.
v and vi are the same thing except they haven't provided you with the prototype. As an example the method prototype for "convertToGrade" may look like this:
public static int convertToGrade(int testResult)
I think you're random array is okay, you would just need another for loop which loops over the size of the array. You would also need to have 3 variables; min, max and sum. So in your for loop you could check if the current number is less than min, if it is, set min as the new number and continue. Always add to the sum so an average can be found doing sum/arraySize.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.