-1

Okay, to make this short, I have 3 java files. The first one is the main, the other two are classes I'm trying to use within my main. For some reason, when I created the other two classes in netbeans by right-clicking on the package, and creating a new class, the classes don't seem to be apart of the main project or "package." In other words, the methods I've created in my other classes, aren't linked to my main. "Point3d, translate, scale, translate, rotate,line3d are the methods giving me errors in my main. Any help would be appreciated, thanks.

first class

package ddunlap_3dcoordinates;
import java.util.*;
/**
*
* @author Aiden
*/
 public class DDunlap_3dCoordinates {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {

int x, y, z;
    x = 2;
    y = 3;
    z = 4;
    Point3d pointA = new Point3d(x, y, z);

    //Let verify our starting conditions
    System.out.println("Initial Points");
    System.out.println(pointA.asString());
    System.out.println("");

    //Translate Test
    System.out.println("Translate all -1");
    pointA.translate(-1, -1, -1);
    System.out.println(pointA.asString());
    System.out.println("");

    //Scale Test
    System.out.println("Scale by 2");
    pointA.scale(2, 2, 2);
    System.out.println(pointA.asString());
    System.out.println("");

    //Rotate
    System.out.println("Rotate 180 with respect to x-axis");
    pointA.rotate(180, "x");
    System.out.println(pointA.asString());
    System.out.println("Rotate 180 with respect to y-axis");
    pointA.rotate(180, "y");
    System.out.println(pointA.asString());
    System.out.println("Rotate 180 with respect to z-axis");
    pointA.rotate(180, "z");
    System.out.println(pointA.asString());
    System.out.println("");

    //Resetting points
    pointA = null;
    pointA = new Point3d(x, y, z);
    Point3d pointB = new Point3d(0, 0, 0);

    Line3d lineAB = new Line3d(pointA, pointB);

    System.out.println("Line AB created");
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");

    //Scale line points
    System.out.println("Scale by 2");
    lineAB.scale(2, 2, 2);
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");

    //Translate by 1,1,1
    System.out.println("Translate by 1,1,1");
    lineAB.translate(1, 1, 1);
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");

    //Translate by -1.-1,-1
    System.out.println("Translate by -1,-1,-1");
    lineAB.translate(-1, -1, -1);
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");

    //Rotate
    System.out.println("Rotate 180 with respect to x-axis");
    lineAB.rotate(180, "x");
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");
    System.out.println("Rotate 180 with respect to y-axis");
    lineAB.rotate(180, "y");
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");
    System.out.println("Rotate 180 with respect to z-axis");
    lineAB.rotate(180, "z");
    System.out.println("Point A: " + lineAB.getA().asString());
    System.out.println("Point B: " + lineAB.getB().asString());
    System.out.println("");
    System.out.println("");

  }

 }

second class

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

public Point3d(double x, double y, double z) {
    //Using this.variable will assign the value to the class.variable
    //This can be avoided by renaming the arguments above
    this.x = x;
    this.y = y;
    this.z = z;
}
//Mutator

void setX(double X) {
    x = X;

}

void sety(double Y) {
    y = Y;

}

void setZ(double X) {
    z = X;

}

void setPoints(double X, double Y, double Z) {
    x = X;
    y = Y;
    z = Z;
}
//Accessor

double getX() {
    return x;
}

double getY() {
    return y;
}

double getZ() {
    return z;
}

//Scale
void scale(double xFactor, double yFactor, double zFactor){
    x = x*xFactor;
    y = y*yFactor;
    z = z*zFactor;
}
//Translate
void translate(double xFactor, double yFactor, double zFactor){
    x += xFactor;
    y += yFactor;
    z += zFactor;

}
//Rotate
void rotate(double theta, String axis){
    //If invalid values are passed reject an notify user

    if(axis.isEmpty() || theta == 0 || axis.length() != 1){
        System.out.println("Error: Invalid args");
        return;
    }

    //Math.trigs expects radians! Convert degrees to radians
    theta = theta * (Math.PI/180);

    //Convert axis to lower
    axis = axis.toLowerCase();

    //x rotation
    if(axis.equals("x")){
        //x = x;
        y = (y * Math.cos(theta) - (z * Math.sin(theta)));
        z = (y * Math.sin(theta)) + (z * Math.cos(theta));
        return;
    }
    //y rotation
    if(axis.equals("y")){
        x = x * Math.cos(theta) + z * Math.sin(theta);
        //y = y;
        //0 minus x is -x
        z = (0-x) * Math.sin(theta) + z * Math.cos(theta);
        return;    
    }
    if(axis.equals("z")){
        x = x * Math.cos(theta) - y * Math.sin(theta);
        y = x * Math.sin(theta) + y * Math.cos(theta);
        //z = z;

    }


}


//Value retrieval for debugging
String asString(){
    return "X: " + x + " Y: " + y + " Z: " + z;

}
}

third class

  public class Line3d {
   Point3d lineA;
   Point3d lineB;

Line3d(Point3d a, Point3d b) {
    lineA = new Point3d(a.getX(), a.getY(), a.getZ());
    lineB = new Point3d(b.getX(), b.getY(), b.getZ());

}

void setA(Point3d a) {
    //Java has a garbage collector and you do not need to do this
    //but setting an object to null will close all references to the object
    //and allow Java GC to clean it up
    lineA = null;
    lineA = new Point3d(a.getX(), a.getY(), a.getZ());

}

void setB(Point3d b) {
    lineB = null;
    lineB = new Point3d(b.getX(), b.getY(), b.getZ());
}

//We already have an object to handle points, using the object will allow us to reuse code
Point3d getA() {

    return lineA;

}

Point3d getB() {

    return lineB;
}

void scale(double xFactor, double yFactor, double zFactor) {
    lineA.scale(xFactor, yFactor, zFactor);
    lineB.scale(xFactor, yFactor, zFactor);

}

void translate(double xFactor, double yFactor, double zFactor) {
    lineA.translate(xFactor, yFactor, zFactor);
    lineB.translate(xFactor, yFactor, zFactor);

}

void rotate(double degrees, String axis){
    lineA.rotate(degrees, axis);
    lineB.rotate(degrees, axis);
}
 }
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
  • 1
    Are the errors you're getting secret errors? Or is the compiler allowing you to share them with us so that we might be able to help you? – ajb Apr 07 '15 at 04:52
  • It's telling me to create the methods mentioned above. When I try to compile, I get this: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - constructor Point3d in class ddunlap_3dcoordinates.Point3d cannot be applied to given types; required: no arguments found: int,int,int reason: actual and formal argument lists differ in length at ddunlap_3dcoordinates.DDunlap_3dCoordinates.main(DDunlap_3dCoordinates.java:23) – Dudley DudeBro Apr 07 '15 at 04:56

4 Answers4

0

Try putting the files in the same folder and in the driver java code (containing the main function) import the classes and then try to run the code again.

Abhinav
  • 1
  • 7
0

I had come up with a similar error in NetBeans. Make sure to add the source files to your project. Then, disable Compile On Save in Project Properties -> Build -> Compiling.

From here.

Community
  • 1
  • 1
wolfram77
  • 2,841
  • 3
  • 23
  • 33
0

If you have a question regarding multiple classes you might want to consider creating a repository on github.com so collaborators can see the file structure you have created.

When using an ide the code you are creating will exist in 3 places on your computer. 1) In plain text in the various packages of the src folder. 2) As lower level instructions in the bin folder. 3) On the object stack for the ide as it displays and manipulates the code.

Now there is really only one you have to worry about and that is the the src. As the object stack exists without you thinking about it and the bin is constructed when you build/run your code. In your source code(src) you should have sub folders, these are your packages. Classes within these packages are able to access classes within the same package with the class name and classes within other packages with longer addresses, for example :

.
├── pack1
│   ├── class1
│   └── class2
└── pack2
    └── class3

The top of class1 one might have something like

package pack1;
import class2;
import pack2.class3;

or to import the entirety of pack2

import pack2.*; 

It looks like all of your classes are in one file... Which is not the way to go. The Idea of object oriented design is that the code is naturally delegated into class objects. Keeping things organized. A intermediate example would be something like this tetris game I put together for a class.

kpie
  • 9,588
  • 5
  • 28
  • 50
  • So you are creating multiple packages and placing the other java files in there ? Damn my professor really confused me then. He's been teaching me the wrong way to do this. – Dudley DudeBro Apr 07 '15 at 05:18
  • Think of the packages as chapters and the classes as pages. (In a book that reads line by line and weaves through chapters) The lack of import statements in your code sets off some alarm bells... – kpie Apr 07 '15 at 05:21
-1
  1. Make sure your all files are in the same package.

2.I think this is the wrong

int x, y, z;
    x = 2;
    y = 3;
    z = 4;
    Point3d pointA = new Point3d(x, y, z);

you can not pass int type parameter it should be double type parameter.

Naasheer
  • 128
  • 2
  • 5
  • Java automatically converts `int` to `double` for you. That is not the problem. – ajb Apr 08 '15 at 05:43