Java x, y coordinates

Discussion in 'Programmer's Corner' started by chrill3123, Feb 13, 2011.

  1. chrill3123

    Thread Starter New Member

    Apr 21, 2010
    9
    0
    Hi everyone:)

    I have made a program that reads two coordinates (x, y) in double, and prints the coordinates to screen in format= (x, y), however this message comes when i try to compile=

    C:\Java Program>javac PositionProg.java
    PositionProg.java:7: cannot find symbol
    symbol : variable x
    location: class PositionProg
    System.out.println(pos1.asString(x, y));
    ^
    PositionProg.java:7: cannot find symbol
    symbol : variable y
    location: class PositionProg
    System.out.println(pos1.asString(x, y));
    ^
    2 errors

    C:\Java Program>

    Here is the code=

    main program

    public class PositionProg
    {
    public static void main(String[] argv)
    {
    Position pos1;
    pos1 = new Position(25.17, 12.14);
    System.out.println(pos1.asString(x, y));
    }
    }

    the position class
    class Position
    {
    public String a, b, c;
    public double x, y;
    public Position() //Constructor
    {
    x = 0.0;
    y = 0.0;
    }
    public Position(double x, double y) //Constructor2
    {
    this.x = x;
    this.y = y;
    }
    public String asString(Double x, Double y)
    {
    a = Double.toString(x);
    b = Double.toString(y);
    c = "("+a+","+b+")";
    return c;
    }
    }

    Please give some advice where I do wrong:).

    Best regards Christian
     
  2. chrill3123

    Thread Starter New Member

    Apr 21, 2010
    9
    0
    I have now solved the problem:)
     
  3. Chieftain

    New Member

    Feb 22, 2011
    2
    0
    am not confirm about ans....but please check this link i think its helpful for u....
    dreamincode . net / forums /topic/ 41671-x-y-coordinates/
     
Loading...