# calculating quadratic formula using netbeans.

Page 1 of 1

## 4 Replies - 7386 Views - Last Post: 23 February 2011 - 06:54 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=218283&amp;s=1d7b10e613edc6543418f822bfd5bb0e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 umrk

• New D.I.C Head

Reputation: 0
• Posts: 11
• Joined: 23-February 11

# calculating quadratic formula using netbeans.

Posted 23 February 2011 - 02:24 PM

```package unit3;

import java.util.Scanner;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Quadratic
{
private int a, b, c;
private double rootOne;
private double rootTwo;

public Quadratic()
//default quadratic
{

rootOne= 0;
rootTwo= 0;

}

public Quadratic(int quadA, int quadB, int quadC)
{
a=quadA;
b=quadB;
c=quadC;
rootOne=0;
rootTwo=0;

}

public void setEquation(int quadA, int quadB, int quadC)
{
rootOne = -(quadB + Math.sqrt(Math.pow(quadB, 2))) - 4 * (quadA * (quadC)) / (2+quadA);
rootTwo = -(quadB - Math.sqrt(Math.pow(quadB, 2))) - 4 * (quadA * (quadC)) / (2+quadA);

}

public void calcRoots( ) // I do not understand what I am supposed to write here since I already expressed the formula and calculated the roots.
{

}

public void print( )
// prints the two roots.
{
System.out.printf( "rootone :: " + "%.2f",  (rootOne));
System.out.printf( "rootTwo :: " + "%.2f",  (rootTwo));

```

}
}

Is This A Good Question/Topic? 0

## Replies To: calculating quadratic formula using netbeans.

### #2 m-e-g-a-z

• Winning

Reputation: 497
• Posts: 1,453
• Joined: 19-October 09

## Re: calculating quadratic formula using netbeans.

Posted 23 February 2011 - 02:31 PM

No need to import the lang classes below, they are imported by default.

```import static java.lang.System.*;
import static java.lang.Math.*;

```

And your question is?
Was This Post Helpful? 0

### #3 umrk

• New D.I.C Head

Reputation: 0
• Posts: 11
• Joined: 23-February 11

## Re: calculating quadratic formula using netbeans.

Posted 23 February 2011 - 02:38 PM

I just don't understand what I am supposed to put inside public void calcRoots().
I already defined the equation using the roots.
Was This Post Helpful? 0

### #4 umrk

• New D.I.C Head

Reputation: 0
• Posts: 11
• Joined: 23-February 11

## Re: calculating quadratic formula using netbeans.

Posted 23 February 2011 - 02:54 PM

```public void calcRoots()
{
}

```

I don't understand that piece of coding and what I am supposed to write inside of it.
Was This Post Helpful? 0

### #5 pbl

• There is nothing you can't do with a JTable

Reputation: 8362
• Posts: 31,955
• Joined: 06-March 08

## Re: calculating quadratic formula using netbeans.

Posted 23 February 2011 - 06:54 PM

I presume your assignment wants you to be able to change the instance variable
```package unit3;

import java.util.Scanner;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Quadratic
{
private int a, b, c;
private double rootOne;
private double rootTwo;

public Quadratic()
//default quadratic
{

rootOne= 0;
rootTwo= 0;

}

public Quadratic(int quadA, int quadB, int quadC)
{
a=quadA;
b=quadB;
c=quadC;
rootOne=0;
rootTwo=0;

}

public void setEquation(int quadA, int quadB, int quadC)
{
a=quadA;
b=quadB;
c=quadC;
}

public void calcRoots( ) 	{

rootOne = -(b + Math.sqrt(Math.pow(b, 2))) - 4 * (a * (c)) / (2+a);
rootTwo = -(b - Math.sqrt(Math.pow(b, 2))) - 4 * (a * (c)) / (2+a);

}

public void print( )
// prints the two roots.
{
System.out.printf( "rootone :: " + "%.2f",  (rootOne));
System.out.printf( "rootTwo :: " + "%.2f",  (rootTwo));

```

And by the way the formula is / 2 * a and not / 2 + a
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }