Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Problem With Program [solved] (http://www.programmingforums.org/showthread.php?t=1106)

Progejad Nov 11th, 2004 8:07 AM

I have to do program which calculates x and y couples using next formulas:

x=(40*cos)+60*Math.cos((2/3)*t);

y=(40*sin)-60*Math.sin((2/3)*t);


the output of the program should look something like this:

x | y

1234 | 3456 // x and y results
2234 | 8923
1256 | 9842

"t" should change after 0,01 step (from -10 to 10)
(So in output there should be 2000 couples of x and y + first line x|y)

I tried to program but got only more confused after hours of trying...biggest problem is that "step" thing...and that "t" should change after every step...
I hope there's anyone that could help me ...

Infinite Recursion Nov 11th, 2004 10:12 AM

Sounds easy enough... Since this is a homework assignment, I'd like to see effort (code) on your end before I contribute code.

The "step" problem, would be a loop with an index variable that increments through from -10 to 10.

Progejad Nov 12th, 2004 4:39 AM

/*at the end my code was like that, but x and y were not right (maybe i did something wrong with x and y calculating
http://www.itcollege.ee/~kkoemets/kodused2...l_51b41c47.gif- x and y should be like that*/

:

//starting my code: 

    public class Hindeline1 {

    public static void main (String [] args) { 

    double x;
    double y;
 
   
    double t;
       

        for (t = -10; t <= (10); t +=0.01)
        {
       
        double sin=Math.sin(t);
    double cos=Math.cos(t);
       
        x=(40*cos)+60*Math.cos((2/3)*t);
 
    y=(40*sin)-60*Math.sin((2/3)*t);
 
       
        System.out.println (x+ "|" +y);
        }
        }

}//End of code


drunkenCoder Nov 13th, 2004 2:29 AM

looks like you got it right to me ... what you wrote calculates x & y correctly (going by the formula you have provided)

Infinite Recursion Nov 13th, 2004 12:51 PM

Looks good. The code achieves your 2000+1 lines of output.
Drunken coder has confirmed the value is correct... you can plug them into a
calculator to confirm further if needed.



:

public class Hindeline1
{
 public static void main (String [] args)
 {
  double x;
  double y;
  double t;

  for (t = -10; t <= 10; t += 0.01)
  {
    double sin=Math.sin(t);
    double cos=Math.cos(t);

    x = (40 * cos) + 60 * Math.cos((2/3)*t);
    y = (40 * sin) - 60 * Math.sin((2/3)*t);

    System.out.println(x + " | " + y);
  }
 }
}



All times are GMT -5. The time now is 12:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC