• 03-01-2009, 05:20 AM
cowboys94
Hello I am new to java and this is part of the first homework that was assigned. I have no clue on how to even approach this problem. Help with either one or both is greatly appreciated.

Create a class called funnyLoops

* ask the user to enter 8 numbers of type double
* use the command line for input and output
* put the 8 numbers in an array of doubles
* print out the contents of the array, in the order of their indices
o that is, element [0], element [1], etc ... to [7]
o use a "for each" loop
* print out the contents of the array, in the reverse order of their indices
o That is, element [7], element [6] etc ... to [0]
o use a for loop
* print every even numbered element
o That is, elements 0, 2, 4, 6
o use a for loop

Write a class called numTest1 that will

* use one method only, the main method
* the method will compute the average test grade
* ask the user how many tests she gave
* assign the input to a varible named numTests of type integer
* print out "The number of tests is: ___"
* declare and create an array of integers called myGrades
o the length of myGrades = the number of test
* print out, using a for loop
o The grade at index 0 is ___
o The grade at index 1 is ___
o The grade at index 2 is ___
o etc
o etc until
o The grade at index [last index] is ___
o ask the user to enter as many grades as there are tests
o as the user enters each grade, assign it to an element of the myGrades array
+ So prompt "Enter the grade: "
+ prompt again: "Enter the grade: "
+ and so on, until all the grades are entered and the array is full
* print out, using a for loop
o The grade at index 0 is ___
o The grade at index 1 is ___
o The grade at index 2 is ___
o etc
o etc until
o The grade at index [last index] is ___
* Using a for loop, find the sum of the grades in the array
* print out the sum: "The sum of the grades is: ___"
* Find the average of the grades in the array
* Print out the average: "The average grade is: ___"
* Say "Goodbye from Your Name"
o put in your actual name.
• 03-01-2009, 05:23 AM
Fubarable
Quote:

I have no clue on how to even approach this problem.
If that's truly the case, then don't mess with the forum. Talk to your teacher without delay. You've much catching up to do. Good luck!
• 03-01-2009, 05:27 AM
cowboys94
i mean this is what i have for the first one so far...

class funnyLoops {
public static void main(String[] args) {
double[] anArray; // declares an array of integers

anArray = new double[8]; // allocates memory for 8 doubles

for (int i = 0;i<= anArray.length;i++)
{
System.out.print("\n\nEnter Score " + (i+1) + ": ");
anArray[i] = UserInput.getInt();
}

} // end main
} // end class
• 03-01-2009, 05:39 AM
Fubarable
And what happens / doesn't happen when you try to run or compile this?
• 03-01-2009, 05:40 AM
Fubarable
Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

Code:

```[cod&#101;]   // your code goes here   // notice how the top and bottom tags are different [/cod&#101;]```
• 03-01-2009, 05:49 AM
cowboys94
ok i'll remember to do that but when i try to compile it, it says...

cannot find symbol
symbol : variable UserInput
location: class funnyLoops
anArray[i] = UserInput.getInt();
^
1 error

Tool completed with exit code 1
• 03-01-2009, 06:03 AM
Fubarable
The error is telling you that it can't find a symbol -- that you're using something that it has no idea what it is. On that line, odds are that it's the UserInput object. What is this supposed to be? If it's a Scanner object, then you'll need to declare it as such. If it's a class with static methods given to you by your teacher to get input, then you may need to import it into your program for it to work.

Best of luck.