write a java application to calculate the exponent value of a number using the following specifications:
.prompt the user to enter an interger value
.pass the interger value to the method square, which squares the number and to a method cubes the number. The result must be returned to the main method.
The main method must print the results along with a suitable message
1
Expert's answer
2012-04-19T07:40:26-0400
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.text.ParseException; public class Problem { private int value; /** * @param args */ public void inputData() throws NumberFormatException{ BufferedReader bReader = new BufferedReader (new InputStreamReader(System.in)); try { System.out.println("Input data value: "); String data = bReader.readLine(); value = Integer.parseInt(data); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public double getSquare(){ return Math.pow(value, 2); } public double getCube(){ return Math.pow(value, 3); } public static void main(String[] args) { // TODO Auto-generated method stub Problem p = new Problem(); try{ p.inputData(); } catch (NumberFormatException e) { System.out.println("Parse exception!"); System.exit(1); } System.out.println("Square: "+p.getSquare()); System.out.println("Cube: "+p.getCube()); } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment