0

Basically, I'm trying to write a program that gives you the discriminant of a quadratic equation with three variables. However when I try to create an object that has the a b and c values of my quadratic it says I didn't create the object. Also I'm new, so if I did something obviously wrong forgive me.

This is the Error I get.

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: at quadratic.equation.solver.QuadraticEquationSolver.main(QuadraticEquationSolver.java:38) Java Result: 1

Below is the code.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quadratic.equation.solver;

/**
 *
 * @author User
 */
public class QuadraticEquationSolver {

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

    class Quadratic {

        int aValue;
        int bValue;
        int cValue;

        public Quadratic(int A, int B, int C) {
            aValue = A;
            bValue = B;
            cValue = C;
        }

        public int calculateDiscriminant(int A, int B, int C) {
            int answer = ((bValue*bValue)+(-4*aValue*cValue));
            return answer;
        }

        Quadratic firstQuad = new Quadratic(7, 5, 3); 

     } 
     System.out.println(firstQuad.calculateDiscriminant);
}
Miklos Aubert
  • 4,405
  • 2
  • 24
  • 33
user2512432
  • 1
  • 1
  • 1

1 Answers1

1

This is more clear solution.

public class Quadratic {


    private int aValue;
    private int bValue;
    private int cValue;

   //constructor
   public Quadratic(int a, int b, int c) {
      aValue = a;
      bValue = b;
      cValue = c;
    }

  public int calculateDiscriminant() {
    int answer = ((bValue*bValue)+(-4*aValue*cValue));
    return answer;
  }

}//end class

And now a test class.

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

        Quadratic firstQuad = new Quadratic(7, 5, 3); 
        System.out.println(firstQuad.calculateDiscriminant());

    } 

}

Or Just

public final class MathUtil {

private MathUtil(){}

 public static int calculateQuadraticDiscriminant(int aValue,int bValue, int cValue) {
        return ((bValue*bValue)+(-4*aValue*cValue));        
 }

}
nachokk
  • 14,363
  • 4
  • 24
  • 53