# How to return all values from a for loop?

• 04-11-2013, 09:51 PM
ilovemysillybanana
How to return all values from a for loop?
Okay so this is my program:

Code:

```package apcsChapter7; import java.util.Scanner; public class PointsOnACircleV1 {         /**         * @param args         */         public static void main(String[] args) {                 // TODO Auto-generated method stub                 Scanner userInput = new Scanner(System.in);                 System.out                                 .println("Would you like to decrease by A: 0.1 or B: 0.01(Iput A or B)");                 String userDecreaseValue = userInput.nextLine();                                 System.out.println("Points On A Circle With A Radius Of One");                 if (userDecreaseValue.equalsIgnoreCase("A")) {                         CircleClass cirlceObject = new CircleClass();                         cirlceObject.ChoiceA();                         cirlceObject.saying();                 } else if (userDecreaseValue.equalsIgnoreCase("B")) {                         CircleClass cirlceObject = new CircleClass();                         cirlceObject.ChoiceB();                         cirlceObject.saying();                 } else {                         System.out.println("Sorry, that's not a choie.");                 }         } }```
Code:

```package apcsChapter7; public class CircleClass {         private double xOne = 1, xTwo = 1, yOne, yTwo;         public double radius = 1;         public double decreaseValue;         public double newRadius;         public double newXOne, newXTwo;         public double ChoiceA() {                 decreaseValue = 0.01;                 return decreaseValue;         }         public double ChoiceB() {                 decreaseValue = 0.001;                 return decreaseValue;         }         public double getRadius() {                 newRadius = Math.pow(radius, 2);                 return newRadius;         }         public double getXOne() {                 newXOne = Math.pow(xOne, 2);                 return newXOne;         }         public double getYOne() {                 yOne = newRadius - newXOne;                 return yOne;         }         public double decreaseX(){                 while(xOne > 0){                         xOne = xOne - decreaseValue;                 }                 return xOne;         }         public void saying() {                 System.out.printf("The Radius is: %f%n", getRadius());                 System.out.printf("The decrease value is: %f%n", decreaseValue);                 System.out                                 .println("Values of X1\tValues of Y1\tValues of X2\tValues of Y2");                 System.out.print("\n"+xOne);         } }```

Okay so I'm trying to make a program that calculates something to do with the pythagoream theorem on circles( I don't understand it either, so don't worry if you don't lol )

The part I need help with is how to return values from a for loop, because the value of a certain variable will be decreased over and over again by 0.01 or 0.001 depending on what the user chooses, but I'm not sure how to return each of those values and print it out, I'm kind of knew to making my programs OOP but I'm trying so if you could help me figure out how to do that it'd be nice if you want to know the instructions to my homework here it is:

Quote:

7.01 Assignment Instructions
Instructions: Write a program to calculate the (x, y) coordinates of points on a circle of radius 1.0.
1. Create a new project called 7.01 Math Class Methods.
2. Create a class called PointsOnACircleV1 in the newly created
folder.
3. The radius of the circle should be 1.0.
4. Use the appropriate Math class methods in your arithmetic expression(s).
5. The value of the x coordinate should change by 0.1 during initial testing. After the program is
working verify that the increment can also be 0.01, or 0.001 with only minor changes to the
code.
6. Display the information in a neatly formatted table. (See expected output.) Use a Formatting
Grid to save time developing the layout for your output.
Background: Recall from your algebra class that the Pythagorean Theorem can be used to
determine the x or y coordinate if you know the radius of the circle and the value of
either x or y.
Assume that you are dealing with a circle whose
If you iterate through successive values of x,
then you can calculate the corresponding value
of y.
Be sure to use methods of the Math class to set
up the arithmetic expression.
Try a few examples with a calculator before
attempting to write the program. For example if
x = .1 and r = 1, what is y? If x = .2 and r = 1,
what is y? If x = .3 and r = 1, what is y?
Expected Output: When your program runs correctly, the output should resemble the following
screen shot. Make sure that the output remains correct if the radius or the increment
between values of x are changed.
Comments include name, date, and purpose of program 1
All calculations correct. 1
Loop(s) written correctly. 1
Math class methods used in arithmetic expressions 2
Program works with other radii and increments. 2
Output formatted with printf(). 1
No compiler or runtime errors 1
Thoughtful PMR included 1