All pastes #363629 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-02-19 16:01 UTC
rendered paste body
/*
 * ArithConsoleJOpt.java
 *
 * Created on January 31, 2007, 11:09 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package javaapplication1;
import java.util.*;
import javax.swing.*;

/**
 *
 * @author Shelly
 */
public class ArithConsoleJOpt {
    // The main method required for an application program
    public static void main( String[] args ) {
        String firstNumber,   // First string entered by user
                secondNumber,  // Second string entered by user
                thirdNumber;    //Third string enetered by user
        int number1 = 0;          // First number to add
        int number2 = 0;          // Second number to add
        int number3 = 0;         //Third number to add
        int sum = 0;              // Sum of number1 and number2
        int difference = 0;             //Difference of sum and number3
        int product = 0;            //Product of sum and number3
        int quotent = 0;            //Quotent of sum and number3
        int modulus = 0;            //Modulus of sum and number3
        
        // Obtain first integer from the user via a popup dialog
        firstNumber = JOptionPane.showInputDialog("Enter first integer"); number1 = Integer.parseInt( firstNumber );
        
        // Obtain second integer from the user via a popup dialog
        secondNumber = JOptionPane.showInputDialog("Enter second integer"); number2 = Integer.parseInt( secondNumber );
        
        //Obtain third integer from user via a popup dialog
        thirdNumber = JOptionPane.showInputDialog("Enter third interger"); number3 = Integer.parseInt(thirdNumber);
        
        // Calculate arithmetic operations
        sum = number1 + number2;
        
        //Obtain difference of sum and number3
        difference = sum - number3;
        
        //Obtain product of sum and number3
        product = sum * number3;
        
        //Obtain quotent of sum and number3
        quotent = sum / number3;
        
        //Obtain modulus of sum and number3
        modulus = sum % number3;
        
        // Create a string for output display
        String outputStr = "The first input number was: " + number1 + "\n" +
                "The second input number was: " + number2 + "\n" +
                "The sum of the two numbers is: " + sum + "\n" +
                "The third input number was:" + number3 + "\n" +
                "The difference of the sum and third input is:" + difference + "\n";
        
        // Display the results via the standard output stream
        System.out.println(outputStr);
        
        // Also display the results via a popup dialog
        JOptionPane.showMessageDialog(null, outputStr, "OUTPUT",
                JOptionPane.INFORMATION_MESSAGE);  }
}