Advertisement
calcpage

C4X13_QuadraticEquation.java

Oct 25th, 2011
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. //QuadraticEquation.java    MrG 2011.1024
  2. public class QuadraticEquation
  3. {
  4.     private int a;
  5.     private int b;
  6.     private int c;
  7.  
  8.     /**
  9.     Constructor: instantiate the integer coefficients of the equation  
  10.     @param a coefficient of x^2
  11.     @param b coefficient of x^1
  12.     @param c coefficient of x^0
  13.     */
  14.     public QuadraticEquation(int a, int b, int c)
  15.     {
  16.         this.a = a;
  17.         this.b = b;
  18.         this.c = c;
  19.     }
  20.  
  21.     /**
  22.     Accessor: calculates the discriminant
  23.     @return b^2-4ac
  24.     */
  25.     public int getDisc()
  26.     {
  27.         return b*b - 4*a*c;
  28.     }
  29.  
  30.     /**
  31.     Accessor: calculates root1 using getDisc()
  32.     @return (-b+sqrt(disc))/2/a
  33.     */
  34.     public double getRoot1()
  35.     {
  36.         return (-b+Math.sqrt(getDisc()))/(2*a);
  37.     }
  38.  
  39.     /**
  40.     Accessor: calculates root2 using getDisc()
  41.     @return (-b-sqrt(disc))/2/a
  42.     */
  43.     public double getRoot2()
  44.     {
  45.         return (-b-Math.sqrt(getDisc()))/(2*a);
  46.     }
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement