hi danpost everyone
i am doing an homework assignment where I have to create a quadratic calculator. the question goes like this;
create a calculator that ;
1. let you know if you can solve a quadratic equation that has a valid solution
2. calculate the solution to the quadratic equation
3 lets you know if you can form a valid triangle
4. calculate the area of a triangle given S length
5. add two fraction and give the answer as a fraction
this is what I have so far can you tell me where I have gone wrong and what i can do to fix it. here is my codes that I use
all help will be appreciated
public Quadratric(){
JTextField inputA, inputB, inputC, displayresults, displayresults2;
this.setTitle("Quadratric Calculator");
JLabel labelA = new JLabel("A", SwingConstants.RIGHT);
inputA = new JTextField(6);//this is seting whatever input into A
JLabel labelB = new JLabel("B", SwingConstants.RIGHT);
inputB = new JTextField(6);
JLabel labelC = new JLabel("C", SwingConstants.RIGHT);
inputC = new JTextField(6);
JLabel labelresults = new JLabel("Results", SwingConstants.RIGHT);
displayresults= new JTextField(6);
displayresults.setEditable(false);
JLabel labelresults2 = new JLabel("", SwingConstants.RIGHT);
displayresults2 = new JTextField(6);
displayresults2.setEditable(false);
JButton jb = new JButton("compute");
jb.addActionListener(this);
Container cont = getContentPane();
cont.setBackground(Color.white);
JPanel pan = new JPanel();
pan.setLayout(new GridLayout(5, 2, 5, 5 ));
pan.add(labelA);
pan.add(inputA);
pan.add(labelB);
pan.add(inputB);
pan.add(labelC);
pan.add(inputC);
pan.add(labelresults);
pan.add(displayresults);
pan.add(displayresults2);
cont.add(pan, BorderLayout.CENTER);
cont.add(jb, BorderLayout.SOUTH);
}
@Override
public void actionPerformed(ActionEvent ae) {
int A = Integer.parseInt(inputA.getText());
int B = Integer.parseInt(inputB.getText());
int C = Integer.parseInt(inputC.getText());
double results = calculateresults(A,B,C);
double results2 = calculateresults(A,B,C);
DecimalFormat df = new DecimalFormat("00.000");
displayresults.setText(df.format(results));
displayresults2.setText(df.format(results2));
}
private double calculateresults(int A, int B, int C){
double result = -B + Math.sqrt((B*B) - (4 * A* C));
return result/(2 * A);
}
private double Calculateresults2(int A, int B, int C){
double results2 = -B -Math.sqrt((B*B) - (4 * A * C));
return results2 /(2 * A);
}
public static void main(String[]args){
Quadratric quad = new Quadratric();
quad.setBounds(300, 300, 350, 250);
quad.setDefaultCloseOperation(EXIT_ON_CLOSE);
quad.setVisible(true);
}
}

