Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your goal is to ask the user for the length of one side of a square, invoke a fu

ID: 3854899 • Letter: Y

Question

Your goal is to ask the user for the length of one side of a square, invoke a functional method called calculateArea that returns the area of the square, invoke a functional method called calculatePerimeter that returns the perimeter of the square, and show the results in a message box. Ask the user via a JOptionPane box for length of one side of a square and parse and save that response into a double variable. Call the area method and save the result in a variable Call the perimeter method and save the result in a variable Display the area and perimeter results in a JOptionPane message box. Take in the length of the side of the square that the user typed. Return the area of the square using the following equation: lengthOfSide * lengthOfSide Take in the length of the side of the square that the user typed. Return the perimeter of the square using the following equation: lengthOfSide * 4

Explanation / Answer


import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog(null, "enter lenghth of the one side of a Square");

//converting input into double

double value = Double.valueOf(input);
double area = calculateArea(value);
double perimeter = calculatePerimeter(value);
JOptionPane.showMessageDialog(null,"area is "+area+ " and perimeter is "+perimeter);
}
public static double calculateArea(double area){
return area * area;
}
public static double calculatePerimeter(double area){
return area * 4;
}
}