Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Implementing Java Interface (30 marks) Given the following Java interface: 1 public interface Irrational { 2 public double computePI (int precision ) ; 3

2. Implementing Java Interface (30 marks) Given the following Java interface: 1 public interface Irrational { 2 public double computePI (int precision ) ; 3 public double computeEulerConstant (int precision ) ; 4 public double computeSquareRootOfTwo (int precision ) ; 5 } Add IrrationalApproximation Java class that implements the interface Irrational? (a) To implement public double computePI(int precision) abstract method use Leibniz formula for (use equation 3 on page 6) (10 marks) = 4 X i=0 (1)i 2 i + 1 = 4 (1 1 3 + 1 5 1 7 + 1 9 . . .) (3) (b) To implement public double computeEulerConstant(int precision) abstract method use the formula for e given by equation 4 on page 6: (10 marks) e = X i=0 1 i! = 1 0! + 1 1! + 1 2! + 1 3! = 1 + 1 + 1 6 + 1 12 + . . . (4) Factorial of non-negative integer N is denoted by N! is given by the following formulae (see equations 5 & 6) N! = 1 2 3 4 (N 1) N (5) 0! = 1 (6) (c) To implement public double computeSquareRootOfTwo(int precision) abstract method use the Babylonian method for approximating 2 (see equation 7 on page 6) (10 marks) Start with an initial approximation X0 Compute a new approximation X1 using X1 = 1 2 (X0 + 2 X0 ) Repeat step until you get an approximation with the specified precision Xn+1 = 1 2 (Xn + 2 Xn ) (7)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago