// Simple averaging program with Dialog Boxes for input/ouput
// References in Liang: 1.11, 2.11; plus more examples in 2.12
// Author: Michael Branicky, 09/06/2007

import javax.swing.JOptionPane;

public class Average3 {
  public static void main(String[] args) {
    // declare variables
    int test1, test2, avg;

    // new String variables
    // declaration/assignment is separated vs. Liang, who likes the shorthand
    String input;  // one and only declaration
    String output; // one and only declaration
    
    // Prompt user to enter initial values in Dialog Boxes
    // I used the shorter version for input, as on page 46 of Liang
    input = JOptionPane.showInputDialog("Enter Test 1 score:"); // 1st assignment
    test1 = Integer.parseInt(input);

    // input is now assigned/used a second time
    input = JOptionPane.showInputDialog("Enter Test 2 score:"); // 2nd assignment
    test2 = Integer.parseInt(input);

    // compute average
    avg = (test1 + test2)/2;

    // print answer in a Dialog Box
    output = "The average is " + avg;  // 1st assignment of output
    JOptionPane.showMessageDialog(null, output);
  }
}
