我的二次规划中的一些方法错误

时间:2016-10-18 20:50:38

标签: java

我相对较新的Java和谷歌没有帮助,这可能是一个常见的新手错误,但我不确定如何进行调试。我的程序相对较小(1级),我认为看看是否有人能弄清楚我的白痴并不会有什么坏处。顺便说一句,这个程序解决了二次方的问题,仅供参考< 3

我的错误(所有错误都来自各自的if语句):

  

错误:类quadneggative中的方法QuadraticFormula不能   适用于给定类型;

     

错误:类quadpositive中的方法QuadraticFormula无法应用于给定类型;

     

错误:类diszero中的方法QuadraticFormula无法应用于给定类型;

我的节目:

import java.lang.*;
import java.util.*;

public class QuadraticFormula {


    public QuadraticFormula() {
    }


    public static void main(String[] args) {
       runnermethod();
    }
    public static double scannermethod()
    {
        Scanner keyboardInput = new Scanner(System.in);
        System.out.print("Please input a value:");
        double val = keyboardInput.nextDouble();
        return val;         
    }

    public static double dis(double aval, double bval, double cval)
    {
        double a = aval;
        double b = bval;
        double c = cval;
        double dis = Math.pow(b,2)-(4*a*c);

        return dis;     
    }

    public static void diszero(double aval, double bval)
    {
        double a = aval;
        double b = bval;

        double quadzero = (-1*b)/(2*a);

        System.out.print("Your real solution is: x ="+quadzero);
    }

    public static void quadpositive(double aval, double bval, double dis)
    {
        double d = dis;
        double a = aval;
        double b = bval;
        double quadsqr = Math.sqrt(d);
        double quadpostop = (-1*b)+quadsqr;
        double quadnegtop = (-1*b)-quadsqr;

        double quadposall = quadpostop/(2*a);
        double quadnegall = quadnegtop/(2*a);
        System.out.print("Your real solutions are: x ="+quadposall+","+quadnegall+"i");
    }

    public static void quadneggative(double aval, double bval, double dis)
    {
        double d = dis;
        double a = aval;
        double b = bval;
        double quadsqr = Math.sqrt(d*(-1));
        double quadpostop = (-1*b)+quadsqr;
        double quadnegtop = (-1*b)-quadsqr;

        double quadposall = quadpostop/(2*a);
        double quadnegall = quadnegtop/(2*a); 
        System.out.print("Your imaginary solutions are: x ="+quadposall+"i,"+quadnegall+"i");
    }

    public static void runnermethod()
    {
        scannermethod();
        double a = scannermethod();
        double b = scannermethod();
        double c = scannermethod();

        dis(a, b, c);

        double disc = dis(a, b, c);

        if(disc < 0)
        {
            quadneggative();
        }

        if(disc > 0)
        {
            quadpositive();
        }

        if(disc == 0)
        {
            diszero();
        }
    }

}

1 个答案:

答案 0 :(得分:0)

您忘记将参数添加到方法中 它应该是:

if(disc < 0) {
    quadneggative(a,b,disc);
}

if(disc > 0) {
    quadpositive(a,b,disc);
}

if(disc == 0) {
    diszero(a,b);
}