Want more features on Pastebin? Sign Up, it's FREE!
Guest

Roots

By: a guest on Nov 19th, 2012  |  syntax: None  |  size: 0.60 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.lang.Math;
  2. public class Roots
  3. {
  4.     private double guess;
  5.     private double a;
  6.     private double n;
  7.     private double epsilon;
  8.    
  9.     public Roots(double a, double n, double epsilon)
  10.     {
  11.         this.a = a;
  12.         this.n = n;
  13.         this.epsilon = epsilon;
  14.         guess = 1;
  15.     }
  16.    
  17.     public boolean hasMoreGuesses()
  18.     {
  19.         if((Math.abs(Math.pow(guess, n) - a)) < epsilon)
  20.         return false;
  21.         else
  22.         return true;
  23.     }
  24.    
  25.     public double nextGuess()
  26.     {
  27.         guess = (guess + a/guess)/2.0;
  28.         return guess;
  29.     }
  30.    
  31.    
  32. }
clone this paste RAW Paste Data