Alberto Rossi
Alberto Rossi

Reputation: 1800

Java subclass doesn't have enough arguments

I am learning Java OOP reading a book, and it doesn't explain very well the sub classes topic. I am trying to make a class that solves a system of equations, you can find the code here.

The class sistemi solves systems of 2 equations and the subclass sistemi3eq solves systems with 3 equations. NetBeans is giving me this error:

enter image description here

I haven't found a lot of documentation. Do you have any suggestion? How could I improve my code?

Upvotes: 0

Views: 65

Answers (3)

Marco Acierno
Marco Acierno

Reputation: 14847

Your class name don't (and can't) have () so why you do extends sistemi()?

Just extends sistemi

Upvotes: 2

Alberto Rossi
Alberto Rossi

Reputation: 1800

I have assigned void at sistemi(double a, double b, double c, double d, double e, double f) and now it works.

public class sistemi {

    private Double x;
    private Double y;

    public void sistemi(double a, double b, double c, double d, double e, double f) {
     //calcolo nella matrice
     double detx = (c*e)-(b*f);
     double dety = (a*f)-(c*d);
     double det = (a*e)-(d*b);

     //calcolo dei risultati x e y del sistema
     if (det != 0) {
      x = detx/det;
      y = dety/det;
     } 
    }

    //funzioni varie
    other code
}

class sistemi3eq extends sistemi {

    private Double x;
    private Double y;
    private Double z;

    //other code    
}

Upvotes: -1

matt
matt

Reputation: 2429

Your subclass is not actually within your parent class. You need to move it within the scope of your parent class. You can't have two separate pubilc classes in one file.

Since the second isn't public, you can still use it that way, but you really shouldn't. You should put it within the sistemi class or in another file.

public class sistemi {
    ...

//this bracket here needs to go at the bottom of the file
//}

    class sistemi3eq extends sistemi {

        ...
    }    
}

Upvotes: 1

Related Questions