0

I'm trying to code something simple that asks the user for a radius and an angle so that it can calculate the cartesian coordinates x and y, but I'm very new to any kind of coding and can't seem to get it right. At the moment, when I try to compile it I have the error: cannot find symbol (the final printf line) I've gone through my lecture slides and searched on google for ages now and nothing seems to work, I feel like I must be missing something super obvious and simple. That or my whole code is a mess, I really don't know what I'm doing here so any help would be appreciated. Is the out.printf written wrong, what am I missing?? Or the following string, I don't fully understand the \n so maybe that's where i've messed up? Any help would be amazing, this is only my second piece of code and I'm really learning through trial by error.

import java.util.Scanner;   //import scanner and math class

class Cartesian
{
 public static void main(String[] args)
 {
 
    // Create a scanner that can read numbers, or words
    Scanner input = new Scanner(System.in);
        System.out.print("Enter the radius");
    double radius = input.nextDouble();
 
    System.out.print("Enter the angle");
    double angle = input.nextDouble();

     //  given formulas
    double xValue = radius*cos(angle);
    double yValue = radius*sin(angle);
 
    // formatted output
    out.printf("x equals %.1f and y equals %.1f \n", (xValue),(yValue));
 }
}


Rosie
  • 81
  • 1
  • 4

1 Answers1

0

So you have code lines: System.out.print("Enter the radius"); and System.out.print("Enter the angle"); ... similarly, your out.printf() should be called from the System object, so you should change out.printf(...); to System.out.printf(...);

I'm not sure your compiler would know cos and sin as well... those might have to change to Math.cos( ) and Math.sin( ) if you get further errors.

JimN
  • 340
  • 2
  • 10
  • Aaah thank you so much for the help, I can't believe it was something so easy! I even tried System.printf beforehand like a fool, it makes so much more sense now!! Thank you for explaining it in an easy to understand and straightforward way :) – Rosie Mar 25 '21 at 03:08