Question: Show the modifications needed to add exponentiation to the class Calculator in Listing 9.12. Use ^ to indicate the exponentiation operator and the method Math.pow

Show the modifications needed to add exponentiation to the class Calculator in Listing 9.12. Use ^ to indicate the exponentiation operator and the method Math.pow to perform the computation.


Listing 9.12.

import java.util.Scanner; /** Simple line-oriented calculator program. The class can also be used to create other calculator programs. */ public class Calculator { private double result; private double precision = 0.0001; // Numbers this close to zero are treated as if equal to zero. public static void main (String []import java.util.Scanner; /** Simple line-oriented calculator program. The class can also be

import java.util.Scanner; /** Simple line-oriented calculator program. The class can also be used to create other calculator programs. */ public class Calculator { private double result; private double precision = 0.0001; // Numbers this close to zero are treated as if equal to zero. public static void main (String [] args) { Calculator clerk = new Calculator (); try { System.out.printin("Calculator is on."); System.out.print ("Format of each line: "); System.out.println("operator space number"); System.out.println("For example: + 3"); System.out.printin("To end, enter the letter e."); clerk.doCalculation (); catch (UnknownOpException e) { clerk.handleUnknownOpException (e); catch (DivideByZeroException e) { clerk.handleDivideByZeroException (e); } System.out.println ("The final result is %3D + clerk.resultValue ()); System.out.println ("Calculator program ending."); } public Calculator () { result = 0;

Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

case THIS ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java An Introduction to Problem Solving and Progra Questions!