Results 1 to 2 of 2
 04112013, 09:51 PM #1Member
 Join Date
 Apr 2013
 Posts
 14
 Rep Power
 0
How to return all values from a for loop?
Okay so this is my program:
Java Code:package apcsChapter7; import java.util.Scanner; public class PointsOnACircleV1 { /** * @param args */ public static void main(String[] args) { // TODO Autogenerated 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."); } } }
Java 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:
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
radius is 1.
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.
Assessment: Your assignment will be graded according to the following rubric.
Grading Rubric Pts
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
Submission: Submit your PointsOnACircle.java file as Assignment 07.01 for a grade.
 04122013, 04:21 PM #2
Re: How to return all values from a for loop?
If you want to return multiple items, add them to an array or a List (or some other data structure such as a Set or a Map depending on your needs) and then return that. But are you sure you want to return multiple items from a function? (I honestly don't know, it just sounds like a strange approach)
How to Ask Questions the Smart Way
Static Void Games  Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads

Cannot return values from hashmap
By uhertz in forum New To JavaReplies: 1Last Post: 06172011, 04:16 PM 
Return values from a while loop
By gaborn415 in forum New To JavaReplies: 7Last Post: 04112011, 05:12 AM 
Return positive values only
By DomBrown in forum New To JavaReplies: 14Last Post: 03312011, 07:48 PM 
Using functions that return values?
By Megapixelz in forum New To JavaReplies: 1Last Post: 04302008, 04:07 AM 
how to return values from hashmap
By oregon in forum New To JavaReplies: 2Last Post: 08012007, 04:56 PM
Bookmarks