4 Replies - 4867 Views - Last Post: 23 February 2011 - 06:54 PM Rate Topic: -----

#1 umrk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

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

Reputation: 8328
  • View blog
  • Posts: 31,857
  • 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