Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Rep Power

    Default 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 Auto-generated method stub
    		Scanner userInput = new Scanner(;
    				.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();
    		} else if (userDecreaseValue.equalsIgnoreCase("B")) {
    			CircleClass cirlceObject = new CircleClass();
    		} 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);
    				.println("Values of X1\tValues of Y1\tValues of X2\tValues of Y2");

    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
    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
    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 file as Assignment 07.01 for a grade.
    Please help if you iknow how to do this :)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default 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 - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Cannot return values from hashmap
    By uhertz in forum New To Java
    Replies: 1
    Last Post: 06-17-2011, 04:16 PM
  2. Return values from a while loop
    By gaborn415 in forum New To Java
    Replies: 7
    Last Post: 04-11-2011, 05:12 AM
  3. Return positive values only
    By DomBrown in forum New To Java
    Replies: 14
    Last Post: 03-31-2011, 07:48 PM
  4. Using functions that return values?
    By Megapixelz in forum New To Java
    Replies: 1
    Last Post: 04-30-2008, 04:07 AM
  5. how to return values from hashmap
    By oregon in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 04:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts