Question

In: Computer Science

in java Write an application that gets two numbers from the user and prints the sum,...

in java

Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.

Solutions

Expert Solution

import javax.swing.JOptionPane;

public class SampleGUI{

public static void main (String args[]){

    int a,b, sum, product, difference, quotient;

    String aVal, bVal;

    //Getting the inputs from Java Dialog box

    aVal = JOptionPane.showInputDialog("Enter first Integer:");

    bVal = JOptionPane.showInputDialog("Enter second Integer:");

   

    a = Integer.parseInt(aVal);

    b = Integer.parseInt(bVal);

    //Calculating the the sum, product, difference and quotient

    sum = a+b ;

    product = a*b;

    difference = a-b;

    quotient = a/b;

   

    //Printing out the result using java Dialog box

    JOptionPane.showMessageDialog(null, "The Sum of "+a+" and "+b+ " is " + sum+ "\nThe Product of "+a+" and "+b+ " is " + product+ "\nThe Difference of "+a+" and "+b+ " is " + difference+"\nThe Quotient of "+a+" and "+b+ " is " + quotient);

}

}

Output:


Related Solutions

use java Write a program that, given two binary numbers represented as strings, prints their sum...
use java Write a program that, given two binary numbers represented as strings, prints their sum in binary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0 Input: Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces. Output: For each pair of binary numbers print to standard...
IN JAVA Write a complete program that asks the user to enter two real numbers from...
IN JAVA Write a complete program that asks the user to enter two real numbers from the console. If both numbers are positive print the product, if both numbers are negative print the quotient, otherwise print INVALID INPUT. Use a nested if; output should be to a dialog and console; use printf to format the console output (for real numbers specify the width and number of digits after the decimal). The output must be labeled. Follow Java conventions, indent your...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199   Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
Write a Java method called printAvg that takes in two floating point numbers and prints out...
Write a Java method called printAvg that takes in two floating point numbers and prints out the average of them.
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
1.Write a Java program that prompts the user for a month and day and then prints...
1.Write a Java program that prompts the user for a month and day and then prints the season determined by the following rules. If an invalid value of month (<1 or >12) or invalid day is input, the program should display an error message and stop. Notice that whether the day is invalid depends on the month! You may assume that the user will never enter anything other than integers (no random strings or floats will be tested.) Tips: Break...
JAVA PROGRAMMING Write a program that ask the user for a number then prints the cube...
JAVA PROGRAMMING Write a program that ask the user for a number then prints the cube of the number. The program should be called CubeNumbers. Use a value returning method with parameter, call the method myCube.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT