-1

I'm trying to implement the next code to multiply a matrix with a point or vector. But I have to use a static times method (obligatory static)

package reto3;

public class Matrix3x3 {
    public double matrix[][];

    public Matrix3x3(double matrix[][]) {
        this.matrix = matrix;
    }

    public Matrix3x3() {
        matrix = new double[3][3];
    }

    public static Point3 times(Matrix3x3 m3, Point3 p3) {
        double p[] = {p3.x, p3.y, p3.w};
        double result[] = new double[3];
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result.length; j++) {
                result[i] = m3.matrix[i][j] * p[j];
            }
        }
        
        return new Point3(result[0], result[1], result[2]);
    }
}
package reto3;

public class Point3 {
    
    public double point[];
    double x;
    double y;
    double w;
    
    public Point3(double x, double y, double w){
        point = new double[3];
        point[0] = x;
        point[1] = y;
        point[2] = w;
        this.x = x;
        this.y = y;
        this.w = w;
    }

    public double[] getPoint() {
        return point;
    }

    public double getX() {
        return point[0];
    }
    
    public double getY() {
        return point[1];
    }

    public double getW() {
        return point[2];
    }

    public void setX(double x) {
        point[0] = x;
    }

    public void setY(double y) {
        point[1] = y;
    }

    public void setW(double w) {
        point[2] = w;
    }
}
package reto3;

public class Main {
    public static void main(String[] args) throws Exception {
        Matrix3x3 matrix = new Matrix3x3();
        double x = 1.5;
        double y = 2.0;
        double w = 3.5;
        Point3 point3 = new Point3(x, y, w);
        Matrix3x3.times(matrix, point3);
        
    }
}

And when I compile the code it shows me the following

src/reto3/Main.java:5: error: cannot find symbol
        Matrix3x3 matrix = new Matrix3x3();
        ^
  symbol:   class Matrix3x3
  location: class Main
src/reto3/Main.java:5: error: cannot find symbol
        Matrix3x3 matrix = new Matrix3x3();
                               ^
  symbol:   class Matrix3x3
  location: class Main
src/reto3/Main.java:9: error: cannot find symbol
        Point3 point3 = new Point3(x, y, w);
        ^
  symbol:   class Point3
  location: class Main
src/reto3/Main.java:9: error: cannot find symbol
        Point3 point3 = new Point3(x, y, w);
                            ^
  symbol:   class Point3
  location: class Main
src/reto3/Main.java:10: error: cannot find symbol
        Matrix3x3.times(matrix, point3);
        ^
  symbol:   variable Matrix3x3
  location: class Main
5 errors

I'm not sure if I'm calling the method correctly or how it should be implemented with the static method.

I'd appreciate your help

Jarvis
  • 1
  • 1

1 Answers1

-1

You need to import all the outside classes so they can be accessed.

So import point3 in matrix3x3 class and Import point3 and matrix3x3 in main class

Use an ide like Intellij to code.. They will take care of this automatically.

Saurabh Nigam
  • 795
  • 6
  • 12