import java.util.StringTokenizer; import javax.swing.JOptionPane; import java.io.*; // for I/O public class TriAreaCalculator { public static void main (String[] args) throws IOException { double a, b, c, s, area; //StringTokenizer tokenizer; //In a dialog box, ask the user to enter numbers. //System.out.println("Please enter three numbers, separated by spaces."); String input = JOptionPane.showInputDialog (null, "Enter an expression," + " separated by spaces.", "A simple addition calculator", JOptionPane.QUESTION_MESSAGE); //tokenize the user input. StringTokenizer tokenizer = new StringTokenizer(input); //parse the user input. a = Double.parseDouble(tokenizer.nextToken()); //b = Double.parseDouble(tokenizer.nextToken()); String op = tokenizer.nextToken(); c = Double.parseDouble(tokenizer.nextToken()); //This is where we might check and see whether the three numbers can be the //sides of a triangle. IF they cannot be, then we should inform the user, ELSE //we should perform the computation. //These two method calls can simply be replaced by the code from those methods. //s = ComputeS(a,b,c); //area = ComputeArea(a,b,c,s); // s = (a + b + c)/2; // area = Math.sqrt(s*(s-a)*(s-b)*(s-c)); //double sum = a + b + c; //area = a + b + c; //we construct the string that we want to output. // String message = "A triangle with sides length " + a + ", " + b // + ", and " + c + "\nhas an area of " + area + ".\n"; String message = "The sum of " + a + " and " + c + " is " + (a + c); //show the message string. JOptionPane.showMessageDialog (null, message, "A simple addition calculator", JOptionPane.ERROR_MESSAGE); } }