Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,412 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,590 people online right now. Registration is fast and FREE... Join Now!




Unknown Reason for Errors: Please Help

 

Unknown Reason for Errors: Please Help, NOT HOMEWORK

wolfman29

3 Jul, 2009 - 03:25 PM
Post #1

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
Hey everyone. My doubleVariableCalculator is not working... need help with it.

Here is the code:
CODE
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;

public class doubleVariableAlgebCalc extends JPanel implements ActionListener {



        Float coefficientX1;
    Float coefficientX2;
    Float coefficientY1;
    Float coefficientY2;
        String afterVariable1First;
    String afterVariable1Second;
        int operatorCheck;
    int operatorCheck2;
        String afterVariable2;
        String afterVariable3;
        Float equals;
    Float equals2;
        Float constant = null;
        Float divisor;
        Float solutionX;
    Float solutionY;
        String textSolution;
    String stringSolution;
    String stringSolutionX;
    String stringSolutionY;
    int nullStringTester = 0;


    protected JTextField equationTextfield = new JTextField(15);
    protected JTextField equationTextfield2 = new JTextField(15);

    protected JLabel equationLabel = new JLabel("Equation #1: ");
    protected JLabel equationLabel2 = new JLabel("Equation #2: ");
    protected JLabel solutionLabel = new JLabel("Solution: ");

    JLabel instructions1 = new JLabel("Please insert your two equations that you want solved of");
    JLabel instructions2 = new JLabel("the formats '4x+2y=10' and '3x-8y=3'. Please use 'x' and 'y' for your variables.");

    JButton solveButton = new JButton("Solve!");

    JTextField solutionTextField = new JTextField(15);

    public doubleVariableAlgebCalc() {

        super(null);

        solveButton.addActionListener(this);

        solutionTextField.setEditable(false);

        //Add components

        add(instructions1);
        add(instructions2);
        add(equationLabel);
    add(equationLabel2);
        add(equationTextfield);
    add(equationTextfield2);
        add(solveButton);
        add(solutionLabel);
        add(solutionTextField);

        Dimension size = instructions1.getPreferredSize();

        size = instructions1.getPreferredSize();
            instructions1.setBounds(130, 75, size.width, size.height);

        size = instructions2.getPreferredSize();
            instructions2.setBounds(75, 90, size.width, size.height);

        size = equationLabel.getPreferredSize();
            equationLabel.setBounds(135, 150, size.width, size.height);

            size = equationTextfield.getPreferredSize();
            equationTextfield.setBounds(210, 150, size.width, size.height);

    size = equationLabel2.getPreferredSize();
            equationLabel2.setBounds(135, 175, size.width, size.height);

            size = equationTextfield2.getPreferredSize();
            equationTextfield2.setBounds(210, 175, size.width, size.height);

            size = solveButton.getPreferredSize();
            solveButton.setBounds(255, 210, size.width, size.height);    

            size = solutionLabel.getPreferredSize();
            solutionLabel.setBounds(135, 250, size.width, size.height);

        size = solutionTextField.getPreferredSize();
        solutionTextField.setBounds(213, 250, size.width, size.height);

    } //Ending constructor

    public void actionPerformed(ActionEvent evt) {

        //Setting Variables

        String equation = equationTextfield.getText();
    String equation2 = equationTextfield2.getText();

    //Where variables used to be


    String solutionText = calculations(equation, equation2);


    solutionTextField.setText(solutionText);

    } //Ending actionListener

    public static void main(String[] args) {

        //Making calculator object
        doubleVariableAlgebCalc doubleVariableAlgebraCalculator = new doubleVariableAlgebCalc();

        //Setting up frame
        JFrame calculator = new JFrame("Double Variable Calculator");
        calculator.setSize(600,400);
          calculator.setVisible(true);
        calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        calculator.setResizable(false);        

        calculator.add(doubleVariableAlgebraCalculator, BorderLayout.CENTER);



    } //Ending main class

    public String calculations(String equation, String equation2) {

    String[] brokenUp = equation.split("x");
    String[] brokenUp2 = equation2.split("x");

    coefficientX1 = Float.parseFloat(brokenUp[0]);
    coefficientX2 = Float.parseFloat(brokenUp2[0]);






    //Finding y-coefficient of equation1    
    
    operatorCheck = equation.indexOf("+");

    if (operatorCheck > 0) {
        String subStringPlusEquation1 = equation.substring(operatorCheck, equation.length());
        String[] brokenUp3 = subStringPlusEquation1.split("y");
        coefficientY1 = Float.parseFloat(brokenUp3[0]);

    } //Ending y-coefficient1 plus check

    else {}

    operatorCheck = equation.indexOf("-");

    if (operatorCheck > 0) {
        String subStringPlusEquation1 = equation.substring(operatorCheck, equation.length());
        String[] brokenUp3 = subStringPlusEquation1.split("y");
        coefficientY1 = (-(Float.parseFloat(brokenUp3[0])));

    } //Ending y-coefficient1 minus check

    else {}





    //Finding y-coefficient of equation2

    operatorCheck2 = equation.indexOf("+");

    if (operatorCheck > 0) {
        String subStringPlusEquation2 = equation2.substring(operatorCheck, equation2.length());
        String[] brokenUp4 = subStringPlusEquation2.split("y");
        coefficientY2 = Float.parseFloat(brokenUp4[0]);

    } //Ending y-coefficient2 plus check

    else {}

    operatorCheck2 = equation.indexOf("-");

    if (operatorCheck > 0) {
        String subStringPlusEquation2 = equation2.substring(operatorCheck, equation2.length());
        String[] brokenUp5 = subStringPlusEquation2.split("y");
        coefficientY2 = (-(Float.parseFloat(brokenUp5[0])));

    } //Ending y-coefficient2 minus check
    
    else {}


    //Finding equals of equation1

    String[] brokenUp6 = equation.split("=");
    equals = Float.parseFloat(brokenUp6[1]);



    //Finding equals of equation2

    String[] brokenUp7 = equation2.split("=");
    equals2 = Float.parseFloat(brokenUp7[1]);





    //Solving for y
    Float newYCoefficient = ((coefficientY1*coefficientX2)-(coefficientY2*coefficientX1));    
    
    Float newEquals = ((equals*coefficientX2)-(equals2*coefficientX1));

    solutionY = newEquals-newYCoefficient;

    stringSolutionY = Float.toString(solutionY);


    //Solving for x
    solutionX = (((equals-(solutionY*coefficientY1))/coefficientX1));

    stringSolutionX = Float.toString(solutionX);

    String solutions = "x= " + stringSolutionX + ", y= " + stringSolutionY;

    return solutions;

    }

} //Ending class


The calculator compiles nicely, but when I input two equations into my calculator of correct format, I still get a BUNCH of errors that I do not understand.

Here are the errors:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at doubleVariableAlgebCalc.actionPerformed(doubleVariableAlgebCalc.java:
195)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
95)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Does anyone know what these mean? Please help.

This post has been edited by wolfman29: 3 Jul, 2009 - 03:26 PM

User is offlineProfile CardPM
+Quote Post


OrganizedChaos

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 07:35 PM
Post #2

D.I.C Head
**

Joined: 29 Nov, 2008
Posts: 135



Thanked: 29 times
My Contributions
The first one is a Null Pointer error. Everything below it is the resulting errors of that single error. You are trying to access data that does not exist. Where that is happening I am not sure - still looking through the code.
User is offlineProfile CardPM
+Quote Post

pbl

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 07:42 PM
Post #3

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
coefficientY2 is not initialized

//Solving for y
System.out.println(coefficientY1);
System.out.println(coefficientX2);
System.out.println(coefficientY2);
System.out.println(coefficientX1);

Float newYCoefficient = ((coefficientY1*coefficientX2)-(coefficientY2*coefficientX1));

3.0
3.0
null
2.0

User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 08:34 PM
Post #4

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
QUOTE(pbl @ 3 Jul, 2009 - 07:42 PM) *

coefficientY2 is not initialized

//Solving for y
System.out.println(coefficientY1);
System.out.println(coefficientX2);
System.out.println(coefficientY2);
System.out.println(coefficientX1);

Float newYCoefficient = ((coefficientY1*coefficientX2)-(coefficientY2*coefficientX1));

3.0
3.0
null
2.0


But I DID initialize it. Someone wanna help me decide what to do? Because it IS initialized in the code.
User is offlineProfile CardPM
+Quote Post

pbl

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 08:49 PM
Post #5

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
You are intializing it in a if() that is probably never true
put a println() everywhere you are intializing it and you will see that you never pass through that path
User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 08:51 PM
Post #6

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
QUOTE(pbl @ 3 Jul, 2009 - 08:49 PM) *

You are intializing it in a if() that is probably never true
put a println() everywhere you are intializing it and you will see that you never pass through that path


Yeah, just tried that. See any issues of why that if() is never getting passed through?
User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 09:09 PM
Post #7

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
Okay. So I just tried that, I just initialized it up at the class-level. It works nicely. However, for some reason, I cannot make either of the y-variables negative.

How do I make a Float negative? I tried multiplying it by -1, adding a minus sign in front... what?
User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 09:25 PM
Post #8

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
By the way, I updated it so all my Float variables are now double variables. Shouldn't make a difference, just figured I might as well.
User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 09:46 PM
Post #9

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
New issue. I tested it, now it displays it if it is negative and such. BUT... now, the numbers are off. Anyone see any problems? I don't >.>

Here is the code:

CODE
package calculator;

import java.io.*;
import java.util.*;
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;

public class doubleVariableCalc extends JPanel implements ActionListener {



        double coefficientX1;
    double coefficientX2;
    double coefficientY1;
    double coefficientY2=Double.parseDouble("1");
        String afterVariable1First;
    String afterVariable1Second;
        int operatorCheck;
    int operatorCheck2;
        String afterVariable2;
        String afterVariable3;
        double equals;
    double equals2;
        double constant = 1.0;
        double divisor;
        double solutionX;
    double solutionY;
        String textSolution;
    String stringSolution;
    String stringSolutionX;
    String stringSolutionY;
    int nullStringTester = 0;
    String equation;
    String equation2;
    int negativeCheckY2;
    double newYCoefficient;


    protected JTextField equationTextfield = new JTextField(15);
    protected JTextField equationTextfield2 = new JTextField(15);

    protected JLabel equationLabel = new JLabel("Equation #1: ");
    protected JLabel equationLabel2 = new JLabel("Equation #2: ");
    protected JLabel solutionLabel = new JLabel("Solution: ");

    JLabel instructions1 = new JLabel("Please insert your two equations that you want solved of");
    JLabel instructions2 = new JLabel("the formats '4x+2y=10' and '3x-8y=3'. Please use 'x' and 'y' for your variables.");

    JButton solveButton = new JButton("Solve!");

    JTextField solutionTextField = new JTextField(15);












    public doubleVariableCalc() {

        super(null);

        solveButton.addActionListener(this);

        solutionTextField.setEditable(false);

        //Add components

        add(instructions1);
        add(instructions2);
        add(equationLabel);
    add(equationLabel2);
        add(equationTextfield);
    add(equationTextfield2);
        add(solveButton);
        add(solutionLabel);
        add(solutionTextField);

        Dimension size = instructions1.getPreferredSize();

        size = instructions1.getPreferredSize();
            instructions1.setBounds(130, 75, size.width, size.height);

        size = instructions2.getPreferredSize();
            instructions2.setBounds(75, 90, size.width, size.height);

        size = equationLabel.getPreferredSize();
            equationLabel.setBounds(135, 150, size.width, size.height);

            size = equationTextfield.getPreferredSize();
            equationTextfield.setBounds(210, 150, size.width, size.height);

    size = equationLabel2.getPreferredSize();
            equationLabel2.setBounds(135, 175, size.width, size.height);

            size = equationTextfield2.getPreferredSize();
            equationTextfield2.setBounds(210, 175, size.width, size.height);

            size = solveButton.getPreferredSize();
            solveButton.setBounds(255, 210, size.width, size.height);    

            size = solutionLabel.getPreferredSize();
            solutionLabel.setBounds(135, 250, size.width, size.height);

        size = solutionTextField.getPreferredSize();
        solutionTextField.setBounds(213, 250, size.width, size.height);

    } //Ending constructor











    public void actionPerformed(ActionEvent evt) {

        //Setting Variables

        equation = equationTextfield.getText();
    equation2 = equationTextfield2.getText();

    //Where variables used to be



    String solutionText = calculations(equation,equation2);


    solutionTextField.setText(solutionText);

    } //Ending actionListener



























    public String calculations(String equation, String equation2) {

    String[] brokenUp = equation.split("x");
    String[] brokenUp2 = equation2.split("x");

    coefficientX1 = Double.parseDouble(brokenUp[0]);
    coefficientX2 = Double.parseDouble(brokenUp2[0]);





    //Finding y-coefficient of equation1    
    
    operatorCheck = equation.indexOf("+");

    if (operatorCheck > 0) {
        String subStringPlusEquation1 = equation.substring(operatorCheck, equation.length());
        String[] brokenUp3 = subStringPlusEquation1.split("y");
        coefficientY1 = Double.parseDouble(brokenUp3[0]);

    } //Ending y-coefficient1 plus check

    else {}

    operatorCheck = equation.indexOf("-");

    if (operatorCheck > 0) {
        String subStringPlusEquation1 = equation.substring(operatorCheck, equation.length());
        String[] brokenUp3 = subStringPlusEquation1.split("y");
        coefficientY1 = ((Double.parseDouble(brokenUp3[0]))*(1));

    } //Ending y-coefficient1 minus check

    else {}





    //Finding y-coefficient of equation2    
    
    operatorCheck = equation2.indexOf("+");

    if (operatorCheck > 0) {
        String subStringPlusEquation2 = equation2.substring(operatorCheck, equation2.length());
        String[] brokenUp4 = subStringPlusEquation2.split("y");
        coefficientY2 = Double.parseDouble(brokenUp4[0]);

    } //Ending y-coefficient2 plus check

    else {}

    operatorCheck = equation2.indexOf("-");

    if (operatorCheck > 0) {
        String subStringMinusEquation2 = equation2.substring(operatorCheck, equation2.length());
        String[] brokenUp5 = subStringMinusEquation2.split("y");
        coefficientY2 = (-(Double.parseDouble(brokenUp5[0])));
        negativeCheckY2 = 1;
        System.out.println("Negative");
        

    } //Ending y-coefficient2 minus check

    else {}









    //Finding equals of equation1

    String[] brokenUp6 = equation.split("=");
    equals = Double.parseDouble(brokenUp6[1]);



    //Finding equals of equation2

    String[] brokenUp7 = equation2.split("=");
    equals2 = Double.parseDouble(brokenUp7[1]);





    //Solving for y

    //Solving for y
System.out.println(coefficientX1);
System.out.println(coefficientX2);
System.out.println(coefficientY1);
System.out.println(coefficientY2);

    if (negativeCheckY2 == 1) {

        coefficientY2 = (0-coefficientY2);

    }    


    newYCoefficient = ((coefficientY1*coefficientX2)-(coefficientY2*coefficientX1));

    
    Double newEquals = ((equals*coefficientX2)-(equals2*coefficientX1));



    solutionY = newEquals-newYCoefficient;

    stringSolutionY = Double.toString(solutionY);


    //Solving for x
    solutionX = (((equals-(solutionY*coefficientY1))/coefficientX1));

    stringSolutionX = Double.toString(solutionX);

    String solutions = "x= " + stringSolutionX + ", y= " + stringSolutionY;

    return solutions;

    }

} //Ending class

User is offlineProfile CardPM
+Quote Post

pbl

RE: Unknown Reason For Errors: Please Help

3 Jul, 2009 - 10:11 PM
Post #10

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
QUOTE(wolfman29 @ 3 Jul, 2009 - 09:09 PM) *

Okay. So I just tried that, I just initialized it up at the class-level. It works nicely. However, for some reason, I cannot make either of the y-variables negative.

How do I make a Float negative? I tried multiplying it by -1, adding a minus sign in front... what?

x = -x;

User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

4 Jul, 2009 - 04:43 PM
Post #11

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
Correction:

This is the code. It still does not register the numbers as negative....

Anyone wanna help me out?
CODE
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;

public class doubleVariableAlgebCalc extends JPanel implements ActionListener {



        double coefficientX1;
    double coefficientX2;
    double coefficientY1;
    double coefficientY2;
        String afterVariable1First;
    String afterVariable1Second;
        int operatorCheck;
    int operatorCheck2;
        String afterVariable2;
        String afterVariable3;
        double equals;
    double equals2;
        double constant = 1.0;
        double divisor;
        double solutionX;
    double solutionY;
        String textSolution;
    String stringSolution;
    String stringSolutionX;
    String stringSolutionY;
    int nullStringTester = 0;
    String equation;
    String equation2;
    int negativeCheckY1=0;
    int negativeCheckY2=0;
    double newYCoefficient;


    protected JTextField equationTextfield = new JTextField(15);
    protected JTextField equationTextfield2 = new JTextField(15);

    protected JLabel equationLabel = new JLabel("Equation #1: ");
    protected JLabel equationLabel2 = new JLabel("Equation #2: ");
    protected JLabel solutionLabel = new JLabel("Solution: ");

    JLabel instructions1 = new JLabel("Please insert your two equations that you want solved of");
    JLabel instructions2 = new JLabel("the formats '4x+2y=10' and '3x-8y=3'. Please use 'x' and 'y' for your variables.");

    JButton solveButton = new JButton("Solve!");

    JTextField solutionTextField = new JTextField(15);












    public doubleVariableAlgebCalc() {

        super(null);

        solveButton.addActionListener(this);

        solutionTextField.setEditable(false);

        //Add components

        add(instructions1);
        add(instructions2);
        add(equationLabel);
    add(equationLabel2);
        add(equationTextfield);
    add(equationTextfield2);
        add(solveButton);
        add(solutionLabel);
        add(solutionTextField);

        Dimension size = instructions1.getPreferredSize();

        size = instructions1.getPreferredSize();
            instructions1.setBounds(130, 75, size.width, size.height);

        size = instructions2.getPreferredSize();
            instructions2.setBounds(75, 90, size.width, size.height);

        size = equationLabel.getPreferredSize();
            equationLabel.setBounds(135, 150, size.width, size.height);

            size = equationTextfield.getPreferredSize();
            equationTextfield.setBounds(210, 150, size.width, size.height);

    size = equationLabel2.getPreferredSize();
            equationLabel2.setBounds(135, 175, size.width, size.height);

            size = equationTextfield2.getPreferredSize();
            equationTextfield2.setBounds(210, 175, size.width, size.height);

            size = solveButton.getPreferredSize();
            solveButton.setBounds(255, 210, size.width, size.height);    

            size = solutionLabel.getPreferredSize();
            solutionLabel.setBounds(135, 250, size.width, size.height);

        size = solutionTextField.getPreferredSize();
        solutionTextField.setBounds(213, 250, size.width, size.height);

    } //Ending constructor











    public void actionPerformed(ActionEvent evt) {

        //Setting Variables

        String equation = equationTextfield.getText();
    String equation2 = equationTextfield2.getText();

    //Where variables used to be


    String solutionText = calculations(equation, equation2);


    solutionTextField.setText(solutionText);

    

    } //Ending actionListener















    public static void main(String[] args) {

        //Making calculator object
        doubleVariableAlgebCalc doubleVariableAlgebraCalculator = new doubleVariableAlgebCalc();

        //Setting up frame
        JFrame calculator = new JFrame("Double Variable Calculator");
        calculator.setSize(600,400);
          calculator.setVisible(true);
        calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        calculator.setResizable(false);        

        calculator.add(doubleVariableAlgebraCalculator, BorderLayout.CENTER);



    } //Ending main class

















    public String calculations(String equation, String equation2) {

    String[] brokenUp = equation.split("x");
    String[] brokenUp2 = equation2.split("x");

    coefficientX1 = Double.parseDouble(brokenUp[0]);
    coefficientX2 = Double.parseDouble(brokenUp2[0]);






    //Finding y-coefficient of equation1    
    
    operatorCheck = equation.indexOf("+");

    if (operatorCheck > 0) {
        String subStringPlusEquation1 = equation.substring(operatorCheck, equation.length());
        String[] brokenUp3 = subStringPlusEquation1.split("y");
        coefficientY1 = Double.parseDouble(brokenUp3[0]);
        negativeCheckY1 = 0;
        System.out.println("Positive1");

    } //Ending y-coefficient1 plus check

    else {}

    operatorCheck = brokenUp[1].indexOf("-");

    if (operatorCheck > 0) {
        String subStringPlusEquation1 = equation.substring(operatorCheck, brokenUp2[1].length());
        String[] brokenUp3 = subStringPlusEquation1.split("y");
        coefficientY1 = (-(Double.parseDouble(brokenUp3[0])));
        negativeCheckY1 = 1;
        System.out.println("Negative1");

    } //Ending y-coefficient1 minus check

    else {}




    //Finding y-coefficient of equation2    
    
    operatorCheck = equation2.indexOf("+");

    if (operatorCheck > 0) {
        String subStringPlusEquation2 = equation2.substring(operatorCheck, equation2.length());
        String[] brokenUp4 = subStringPlusEquation2.split("y");
        coefficientY2 = Double.parseDouble(brokenUp4[0]);
        negativeCheckY2 = 0;
        System.out.println("Positive2");

    } //Ending y-coefficient2 plus check

    else {}

    operatorCheck = brokenUp2[1].indexOf("-");

    if (operatorCheck > 0) {
        String subStringMinusEquation2 = equation2.substring(operatorCheck, brokenUp2[1].length());
        String[] brokenUp5 = subStringMinusEquation2.split("y");
        coefficientY2 = (-(Double.parseDouble(brokenUp5[0])));
        negativeCheckY2 = 1;
        System.out.println("Negative2");
        

    } //Ending y-coefficient2 minus check

    else {}

    //Finding equals of equation1

    String[] brokenUp6 = equation.split("=");
    equals = Double.parseDouble(brokenUp6[1]);



    //Finding equals of equation2

    String[] brokenUp7 = equation2.split("=");
    equals2 = Double.parseDouble(brokenUp7[1]);



    //Solving for y

    if (negativeCheckY1 == 1) {

        coefficientY1 = (0-coefficientY1);
    }


    if (negativeCheckY2 == 1) {

        coefficientY2 = (0-coefficientY2);

    }

    System.out.println(coefficientX1+", "+coefficientY1+", "+coefficientX2+", and "+coefficientY2);


    double newYCoefficient = ((coefficientY1*coefficientX2)-(coefficientY2*coefficientX1));    
    
    double newEquals = ((equals*coefficientX2)-(equals2*coefficientX1));

    solutionY = newEquals-newYCoefficient;

    stringSolutionY = Double.toString(solutionY);


    //Solving for x
    solutionX = (((equals-(solutionY*coefficientY1))/coefficientX1));

    stringSolutionX = Double.toString(solutionX);

    String solutions = "x= " + stringSolutionX + ", y= " + stringSolutionY;

    return solutions;

    }

} //Ending class


This post has been edited by wolfman29: 4 Jul, 2009 - 05:18 PM
User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

5 Jul, 2009 - 02:54 PM
Post #12

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
Anyone?
User is offlineProfile CardPM
+Quote Post

wolfman29

RE: Unknown Reason For Errors: Please Help

6 Jul, 2009 - 08:57 PM
Post #13

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 46



Thanked: 1 times
My Contributions
Someone please help >.>
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:11PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month