-1

Here's the new coding that I re-did:

ThreeDPoint.java

public class ThreeDPoint{

private double x, y, z;

public threeDPoint(){
    coordX=0;
    coordY=0;
    coordZ=0;
}

public threeDPoint(double x, double y, double z){
    coordX = x;
    coordY = y;
    coordZ = z;
}

public double getCoord(double x, double y, double z){
    return coordX;
    return coordY;
    return coordZ;
}

}

Main.java

import java.util.Scanner;

public class Main{

      double coordX, coordY, coordZ;

public static void main(String[] args){

    threeDPoint myThreeDPoint=new threeDPoint();

    Scanner sc=new Scanner(System.in);
    String coordX, coordY, coordZ;

    System.out.println("Input Coordinate X");
    myThreeDPoint.coordX(sc.nextDouble());

    System.out.println("Input Coordinate Y");
    myThreeDPoint.coordY(sc.nextDouble());

    System.out.println("Input Coordinate Z");
    myThreeDPoint.coordZ(sc.nextDouble());


}

}

It gave me these errors: Build Output: C:\Users\BurneySoo\Documents\Main.java:8: error: cannot find symbol threeDPoint myThreeDPoint=new threeDPoint(); ^ symbol: class threeDPoint location: class Main C:\Users\BurneySoo\Documents\Main.java:8: error: cannot find symbol threeDPoint myThreeDPoint=new threeDPoint(); ^ symbol: class threeDPoint location: class Main 2 errors

General Output: Error: Could not find or load main class Main

What am I doing wrong?


Thanks so very much for the codes Gagandeep. Somehow I tried them but it gave out more errors than what I had before.

C:\Users\BurneySoo\Documents\ThreeDPoint.java:5: error: invalid method declaration; return type required

public threeDPoint(){
       ^

C:\Users\BurneySoo\Documents\ThreeDPoint.java:11: error: invalid method declaration; return type required

public threeDPoint(double x, double y, double z){
       ^

C:\Users\BurneySoo\Documents\Main.java:14: error: cannot find symbol

myTreeDPoint.coordX(sc.nextLine());
^

symbol: variable myTreeDPoint location: class Main

C:\Users\BurneySoo\Documents\Main.java:17: error: cannot find symbol

myTreeDPoint.coordY(sc.nextLine());
^

symbol: variable myTreeDPoint location: class Main

C:\Users\BurneySoo\Documents\Main.java:20: error: cannot find symbol

myTreeDPoint.coordZ(sc.nextLine());
^

symbol: variable myTreeDPoint location: class Main

C:\Users\BurneySoo\Documents\Main.java:22: error: non-static variable coordY cannot be referenced from a static context

myThreeDPoint.setCoord(coordX, coordY, coordZ);
                               ^

C:\Users\BurneySoo\Documents\Main.java:22: error: non-static variable coordZ cannot be referenced from a static context

myThreeDPoint.setCoord(coordX, coordY, coordZ);
                                       ^

C:\Users\BurneySoo\Documents\Main.java:22: error: method setCoord in class ThreeDPoint cannot be applied to given types;

myThreeDPoint.setCoord(coordX, coordY, coordZ);
             ^

required: double,double,double found: String,double,double reason: actual argument String cannot be converted to double by method invocation conversion

C:\Users\BurneySoo\Documents\ThreeDPoint.java:6: error: cannot find symbol

    coordX=0;
    ^

symbol: variable coordX location: class ThreeDPoint

C:\Users\BurneySoo\Documents\ThreeDPoint.java:7: error: cannot find symbol

    coordY=0;
    ^

symbol: variable coordY location: class ThreeDPoint

C:\Users\BurneySoo\Documents\ThreeDPoint.java:8: error: cannot find symbol

    coordZ=0;
    ^

symbol: variable coordZ location: class ThreeDPoint

C:\Users\BurneySoo\Documents\ThreeDPoint.java:12: error: cannot find symbol

    coordX = x;
    ^

symbol: variable coordX location: class ThreeDPoint

C:\Users\BurneySoo\Documents\ThreeDPoint.java:13: error: cannot find symbol

    coordY = y;
    ^

symbol: variable coordY location: class ThreeDPoint

C:\Users\BurneySoo\Documents\ThreeDPoint.java:14: error: cannot find symbol

    coordZ = z;
    ^

symbol: variable coordZ location: class ThreeDPoint

14 errors

And It still won't prompt me to input coordinate X in the general output. it only gave me:

Error: Could not find or load main class Main

burneyjsoo
  • 1
  • 1
  • 3
  • Are you trying to set coordX to the value you get in the main? – Lucas Mar 16 '12 at 08:23
  • Please do learn Java Naming Conventions, Class name must be in Pascal Case, i.e. First Letter Capitalized and every subsequent word starts with a capitalized alphabet, and variable names should be in Camel Case, i.e. first letter in small case and every first alphabet of a subsequent word is capitalized :-) – nIcE cOw Mar 16 '12 at 08:32
  • Lucas: Yes. The Main.java is going to be where I'll be inputting the coordinates. – burneyjsoo Mar 16 '12 at 09:42
  • @burneyjsoo : See my latest edit, hopefully that will help you in this :-) – nIcE cOw Mar 16 '12 at 10:05

2 Answers2

0

The problem here is that you are not calling a constructor, you're trying to call a method.

Make a constructor for your threeDPoint class, and then use a setter to set the field coordX. You can't call

threeDPoint myThreeDPoint=new coordX();

Because this is a method, not a constructor. What you want is in your threeDPoint class a constructor like so:

    public threeDPoint(args){
//dostuff
}

and then a setter to set your Coords like

public void setCoordx(double coordx){
this.coordx = coordx}

Also, as a matter of Data hiding, make sure to delcare your fields as private or protected.

protected double coordX;
Lucas
  • 5,071
  • 1
  • 18
  • 17
0

You have to write

threeDPoint myThreeDPoint=new threeDPoint("Send Arguments Here");

inside your main method, to make an object, now using this object you have to access your method myThreeDPoint.coordX(11.11);

Change your ThreeDPoint class to this :

public class ThreeDPoint
{
    private double x, y, z;

    public ThreeDPoint()
    {
        this.x = 0;
        this.y = 0;
        this.z = 0;
    }

    public ThreeDPoint(double x, double y, double z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public double getCoordX()
    {
        return this.x;
    }

    public double getCoordY()
    {
        return this.y;
    }

    public double getCoordZ()
    {
        return this.z;
    }
}

Now make objects of this class as

ThreeDPoint myThreeDPoint = new ThreeDPoint();

So your Main Class will look like this :

import java.util.Scanner;
public class Main
{
    double coordX, coordY, coordZ;

    public static void main(String[] args)
    {
        ThreeDPoint myThreeDPoint = new ThreeDPoint();

        Scanner sc=new Scanner(System.in);
        String coordX, coordY, coordZ;

        System.out.println("Input Coordinate X");
        coordX = sc.nextDouble();

        System.out.println("Input Coordinate Y");
        coordY = sc.nextDouble();

        System.out.println("Input Coordinate Z");
        coordZ = sc.nextDouble();

        // This will initialize your Constructor with Arguments.
        ThreeDPoint myThreeDPointArgConst = new ThreeDPoint(coordX, coordY, coordZ);

        coordX = myThreeDPointArgConst.getCoordX();
        System.out.println("Co-ordinate X is : " + coordX);

        coordY = myThreeDPointArgConst.getCoordY();
        System.out.println("Co-ordinate Y is : " + coordY);

        coordZ = myThreeDPointArgConst.getCoordZ();
        System.out.println("Co-ordinate Z is : " + coordZ);        

        // This will initialize the no-arg constructor.
        ThreeDPoint myThreeDPoint = new ThreeDPoint();

        coordX = myThreeDPoint.getCoordX();
        System.out.println("Co-ordinate X is : " + coordX);

        coordY = myThreeDPoint.getCoordY();
        System.out.println("Co-ordinate Y is : " + coordY);

        coordZ = myThreeDPoint.getCoordZ();
        System.out.println("Co-ordinate Z is : " + coordZ);        
    }
}
nIcE cOw
  • 24,468
  • 7
  • 50
  • 143
  • I've updated my latest coding above, below the old coding. I still have errors, and it won't let me input coordinate x anymore. instead, it game me errors instead. What am I doing wrong? – burneyjsoo Mar 16 '12 at 09:36
  • See the names of your class `ThreeDPoint` you changed it to the `Pascal Case` but you forgot to rename your `constructors`, they are like `threeDPoint`, hence they not referring to a constructor, hence write them as `public ThreeDPoint(){ coordX=0; coordY=0; coordZ=0; }` – nIcE cOw Mar 16 '12 at 09:42