Java 爪哇元';t识别字符串“-1“;在线方程程序。请参阅「;方程式;行动指令

Java 爪哇元';t识别字符串“-1“;在线方程程序。请参阅「;方程式;行动指令,java,math,line,equation,Java,Math,Line,Equation,我的Java程序无法正确处理字符串中的-1。它跳过了我在e.getActionCommand()中针对“等式”的所有if语句。我尝试从字符串中创建一个字符数组并处理字符[0],但也没有成功 if ("equation".equals(e.getActionCommand())) { if (interceptB != "0" && slopeX == "1") { if (strIntercept != ""

我的Java程序无法正确处理字符串中的-1。它跳过了我在e.getActionCommand()中针对“等式”的所有if语句。我尝试从字符串中创建一个字符数组并处理字符[0],但也没有成功

    if ("equation".equals(e.getActionCommand()))
    {
        if (interceptB != "0" && slopeX == "1")
        {
            if (strIntercept != "")
            {
                String slash = "[/]";
                String[] slashedUp = interceptB.split(slash);
                float numer = new Float(slashedUp[0]);
                float  denomer = new Float(slashedUp[1]);
                float fl = numer / denomer;
                String minus = "[-]";
                String[] splitUp = interceptB.split(minus);
                if (fl > 0)
                {
                    textEquation.setText("y = x + " + interceptB);
                }
                else if (fl < 0)
                {
                    textEquation.setText("y = x - " + splitUp[1]);
                }
            }

            else
            {
                float numb = new Float(interceptB);
                String minus = "[-]";
                String[] splitUp = interceptB.split(minus);
                if (numb > 0)
                {
                    textEquation.setText("y = x + " + interceptB);
                }
                else if (numb < 0)
                {
                    textEquation.setText("y = x - " + splitUp[1]);
                }
            }
        }
        else if (interceptB != "0" && slopeX == "-1")
        {
            if (strIntercept != "")
            {
                String slash = "[/]";
                String[] slashedUp = interceptB.split(slash);
                float numer = new Float(slashedUp[0]);
                float  denomer = new Float(slashedUp[1]);
                float fl = numer / denomer;
                String minus = "[-]";
                String[] splitUp = interceptB.split(minus);
                if (fl > 0)
                {
                    textEquation.setText("y = -x + " + interceptB);
                }
                else if (fl < 0)
                {
                    textEquation.setText("y = -x - " + splitUp[1]);
                }
            }

            else
            {
                float numb = new Float(interceptB);
                String minus = "[-]";
                String[] splitUp = interceptB.split(minus);
                if (numb > 0)
                {
                    textEquation.setText("y = -x + " + interceptB);
                }
                else if (numb < 0)
                {
                    textEquation.setText("y = -x - " + splitUp[1]);
                }
            }
        }
        else if (slopeX != "0" && interceptB == "0")
        {
            if (slopeX == "1")
            {
                textEquation.setText("y = x");
            }
            else if (slopeX == "-1")
            {
                textEquation.setText("y = -x");
            }
            else
            {
                textEquation.setText("y = " + slopeX + "x");
            }
        }
        else if (slopeX == "0" && interceptB != "0")
        {
            textEquation.setText("y = " + interceptB);
        }
        else
        {
            if (strIntercept != "")
            {
                String slash = "[/]";
                String[] slashedUp = interceptB.split(slash);
                float numer = new Float(slashedUp[0]);
                float  denomer = new Float(slashedUp[1]);
                float fl = numer / denomer;
                String minus = "[-]";
                String[] splitUp = interceptB.split(minus);
                if (fl > 0)
                {
                    textEquation.setText("y = " + slopeX + "x" + " + " + interceptB);
                }
                else if (fl < 0)
                {
                    textEquation.setText("y = " + slopeX + "x" + " - " + splitUp[1]);
                }
            }

            else
            {
                float numb = new Float(interceptB);
                String minus = "[-]";
                String[] splitUp = interceptB.split(minus);
                if (numb > 0)
                {
                    textEquation.setText("y = " + slopeX + "x" + " + " + interceptB);
                }
                else if (numb < 0)
                {
                    textEquation.setText("y = " + slopeX + "x" + " - " + splitUp[1]);
                }
            }
        }
    }
    if ("reset".equals(e.getActionCommand()))
    {
        point2.setEnabled(false);
        getSlope.setEnabled(false);
        getIntercept.setEnabled(false);
        totalEquation.setEnabled(false);
        firstPoint = null; 
        secondPoint = null; 
        slope = null;
        totalSlope = null;
        strIntercept = null; 
        slopeX = null; 
        interceptB = null;
        x1 = 0; 
        x2 = 0; 
        y1 = 0;
        y2 = 0; 
        slopex = 0; 
        slopey = 0; 
        simplifiedSlope = 0; 
        mx = 0; 
        totalMx = 0; 
        intercept = 0; 
        ySide = 0; 
        totalY = 0;
        textField1.setText("");
        textField2.setText("");
        textSlope.setText("");
        textIntercept.setText("");
        textEquation.setText("");
    }
}

public void GetFirstPoint()
{
    firstPoint = textField1.getText();
    String comma = "[,]";
    String[] x1Y1 = firstPoint.split(comma);
    x1 = new Float(x1Y1[0]);
    y1 = new Float(x1Y1[1]);
}

public void GetSecondPoint()
{
    secondPoint = textField2.getText();
    String comma = "[,]";
    String[] x2y2 = secondPoint.split(comma);
    x2 = new Float(x2y2[0]);
    y2 = new Float(x2y2[1]);
}   

public void GetSlope()
{
    slopey = y2 - y1;
    slopex = x2 - x1;

    if (slopey < 0 && slopex < 0)
    {
        slopey = -slopey;
        slopex = -slopex;
    }
    if (slopex < 0)
    {
        slopey = -slopey;
        slopex = -slopex;
    }
    int slopeGCF = calcGCF(slopey, slopex);

    if (slopey % slopex == 0)
    {
        simplifiedSlope = (int)slopey/(int)slopex;
        totalSlope = "";
    }
    else if (slopey % slopex != 0 && slopeGCF > 0)
    {
        slopey = slopey / slopeGCF;
        slopex = slopex / slopeGCF;
        String slopeY = RoundUp(slopey);
        String slopeX = RoundUp(slopex);
        totalSlope = slopeY + "/" + slopeX;
    }
    else
    {
        String slopeY = RoundUp(slopey);
        String slopeX = RoundUp(slopex);
        totalSlope = slopeY + "/" + slopeX;
    }
}

public void GetIntercept()
{
    if (totalSlope == "")
    {
        mx = simplifiedSlope * x1;
        intercept = y1 - mx;
        strIntercept = "";
    }

    else if (totalSlope != "")
    {
        mx = slopey * x1;

        if (mx % slopex == 0)
        {
            totalMx = mx / slopex;
            intercept = y1 - totalMx;
            strIntercept = "";
        }
        else
        {
            ySide = y1 * slopex;
            totalY = ySide - mx;
            float interceptGCF = calcGCF(totalY, slopex);
            float ceptGCFx = 0;
            float ceptGCFy = 0;
            if (totalY % slopex == 0)
            {
                intercept = (int)totalY / (int)slopex;
                strIntercept = "";
            }

            else if (totalY % slopex != 0 && interceptGCF > 0)
            {
                ceptGCFy = totalY / interceptGCF;
                ceptGCFx = slopex / interceptGCF;
                strIntercept = RoundUp(ceptGCFy) + "/" + RoundUp(ceptGCFx);
            }
            else
            {
                strIntercept = RoundUp(totalY) + "/" + RoundUp(slopex);
            }
        }
    }
}

public int calcGCF(float num, float denom)
{   
    float s;

    if (num < 0)
    {
        num = -num;
    }

    else if (denom < 0)
    {
        denom = -denom;
    }

    if (num > denom)
    {
        s = denom;
    }

    else
    {
        s = num;
    }

    if (s > 0)
    {
        for (float i = s; i > 0; i--)
        {
            if ((num % i == 0) && (denom % i == 0))
            {
                return (int)i;
            }
        }
    }
    return -1;
}

public String RoundUp(float f)
{
    int i = (int)f;
    String valToStore = (i==f) ? String.valueOf(i) : String.valueOf(f);
    return valToStore;
}
}
if(“等式”.equals(例如getActionCommand()))
{
如果(截取b!=“0”和&slopeX==“1”)
{
如果(strIntercept!=“”)
{
字符串斜杠=“[/]”;
字符串[]slashedUp=interceptB.split(斜杠);
浮点数=新浮点数(slashedUp[0]);
浮点去噪器=新浮点(slashedUp[1]);
浮点数fl=数值/去噪数;
字符串减号=“[-]”;
String[]splitUp=interceptB.split(减);
如果(fl>0)
{
textEquation.setText(“y=x+”+b);
}
else if(fl<0)
{
textEquation.setText(“y=x-”+拆分[1]);
}
}
其他的
{
浮点数=新浮点数(b);
字符串减号=“[-]”;
String[]splitUp=interceptB.split(减);
如果(麻木>0)
{
textEquation.setText(“y=x+”+b);
}
否则如果(麻木<0)
{
textEquation.setText(“y=x-”+拆分[1]);
}
}
}
else if(interceptB!=“0”和&slopeX==“1”)
{
如果(strIntercept!=“”)
{
字符串斜杠=“[/]”;
字符串[]slashedUp=interceptB.split(斜杠);
浮点数=新浮点数(slashedUp[0]);
浮点去噪器=新浮点(slashedUp[1]);
浮点数fl=数值/去噪数;
字符串减号=“[-]”;
String[]splitUp=interceptB.split(减);
如果(fl>0)
{
textEquation.setText(“y=-x+”+b);
}
else if(fl<0)
{
setText(“y=-x-”+拆分[1]);
}
}
其他的
{
浮点数=新浮点数(b);
字符串减号=“[-]”;
String[]splitUp=interceptB.split(减);
如果(麻木>0)
{
textEquation.setText(“y=-x+”+b);
}
否则如果(麻木<0)
{
setText(“y=-x-”+拆分[1]);
}
}
}
else if(slopeX!=“0”&&interceptB==“0”)
{
如果(斜率=“1”)
{
textEquation.setText(“y=x”);
}
否则如果(slopeX==“-1”)
{
textEquation.setText(“y=-x”);
}
其他的
{
textEquation.setText(“y=“+slopeX+”x”);
}
}
else if(slopeX==“0”&&interceptB!=“0”)
{
textEquation.setText(“y=”+b);
}
其他的
{
如果(strIntercept!=“”)
{
字符串斜杠=“[/]”;
字符串[]slashedUp=interceptB.split(斜杠);
浮点数=新浮点数(slashedUp[0]);
浮点去噪器=新浮点(slashedUp[1]);
浮点数fl=数值/去噪数;
字符串减号=“[-]”;
String[]splitUp=interceptB.split(减);
如果(fl>0)
{
textEquation.setText(“y=“+slopeX+”x“+”+”b);
}
else if(fl<0)
{
textEquation.setText(“y=”+slopeX+“x”+“-”+splitUp[1]);
}
}
其他的
{
浮点数=新浮点数(b);
字符串减号=“[-]”;
String[]splitUp=interceptB.split(减);
如果(麻木>0)
{
textEquation.setText(“y=“+slopeX+”x“+”+”b);
}
否则如果(麻木<0)
{
textEquation.setText(“y=”+slopeX+“x”+“-”+splitUp[1]);
}
}
}
}
如果(“reset.”等于(例如getActionCommand())
{
点2.setEnabled(错误);
getSlope.setEnabled(false);
getIntercept.setEnabled(false);
totalEquation.setEnabled(假);
firstPoint=null;
secondPoint=null;
斜率=零;
总斜率=零;
strIntercept=null;
slopeX=null;
b=null;
x1=0;
x2=0;
y1=0;
y2=0;
slopex=0;
slopey=0;
简化斜率=0;
mx=0;
totalMx=0;
截距=0;
Iside=0;
总Y=0;
textField1.setText(“”);
textField2.setText(“”);
textSlope.setText(“”);
textIntercept.setText(“”);
textEquation.setText(“”);
}
}
public void GetFirstPoint()
{
firstPoint=textField1.getText();
字符串逗号=“[,]”;
字符串[]x1Y1=firstPoint.split(逗号);
x1=新浮点数(x1Y1[0]);
y1=新浮动(x1Y1[1]);
}
public void GetSecondPoint()
{
secondPoint=textField2.getText();
字符串逗号=“[,]”;
字符串[]x2y2=secondPoint.split(逗号);
x2=新浮点数(x2y2[0]);
y2=新浮点数(x2y2[1]);
}   
公共斜坡(
{
slopey=y2-y1;
slopex=x2-x1;
if(slopey<0&&slopex<