my program is supposed to include The three sides of the triangle formatted to two decimal places The perimeter formatted to one decimal place The area formatted to one decimal place The unformatted area. It does run, but it is not decimal formatted. I have read my book to try and figure out how to do this, but it doesn't make since to me. Can someone tell me how I would do this?
import javax.swing.JOptionPane; import java.util.*; import java.text.DecimalFormat; import java.util.StringTokenizer; public class ShelbyHarms_3_03 { public static void main (String [] args) { double a, b, c; //Input sides of triangle double x; //Perimeter of triangle double area; //Area of triangle String inputStr; StringTokenizer st; //Enter sides of the triangle separated by spaces inputStr = JOptionPane.showInputDialog("Enter sides of the triangle separated by spaces"); st = new StringTokenizer(inputStr); a = Double.parseDouble(st.nextToken()); b = Double.parseDouble(st.nextToken()); c = Double.parseDouble(st.nextToken()); DecimalFormat formatter = new DecimalFormat("0.00"); JOptionPane.showMessageDialog(null,"Your three triangle lengths are: " + '\n' + a + '\n' + b + '\n' + c); JOptionPane.showMessageDialog(null,"The area of your triangle is: " + ShelbyHarms302.triangleArea(a, b, c)); } public static double triangleArea (double a, double b, double c) { double s = (a + b + c)/2.0; double x = ((s) * (s-a) * (s-b) * (s-c)); double area = Math.sqrt(x); return area; } // End main() } // End class