Answer to Question #8510 in Java | JSP | JSF for Fulbert

Question #8510
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());
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS