Advertisement
calcpage

APCS2012_C5X1_Quad.java

Oct 26th, 2012
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.04 KB | None | 0 0
  1. //Quad.java MrG 2012.1024
  2. public class Quad
  3. {
  4.     private double a;
  5.     private double b;
  6.     private double c;
  7.  
  8.     /**
  9.     Constructor
  10.     @param a the coefficient of x^2
  11.     @param b the coefficient of x^1
  12.     @param c the coefficient of x^0
  13.     */
  14.     public Quad(double a, double b, double c)
  15.     {
  16.         this.a = a;
  17.         this.b = b;
  18.         this.c = c;
  19.     }
  20.  
  21.     /**
  22.     Accessor
  23.     @return the Discriminant
  24.     */
  25.     public double disc()
  26.     {
  27.         return b*b-4*a*c;
  28.     }
  29.  
  30.     /**
  31.     Accessor
  32.     preCondition: disc()>=0
  33.     @return first Real root
  34.     */
  35.     public double root1()
  36.     {
  37.         return (-b+Math.sqrt(disc()))/(2*a);
  38.     }
  39.  
  40.     /**
  41.     Accessor
  42.     preCondition: disc()>=0
  43.     @return second Real root
  44.     */
  45.     public double root2()
  46.     {
  47.         return (-b-Math.sqrt(disc()))/(2*a);
  48.     }
  49.  
  50.     /**
  51.     Accessor
  52.     preCondition: disc()<0
  53.     @return coefficient of real part of Complex root
  54.     */
  55.     public double real()
  56.     {
  57.         return -b/(2*a);
  58.     }
  59.  
  60.     /**
  61.     Accessor
  62.     preCondition: disc()<0
  63.     @return coefficient of imaginary part of Complex root
  64.     */
  65.     public double imag()
  66.     {
  67.         return Math.sqrt(Math.abs(disc()))/(2*a);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement