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 java application that will read a set of values from the user and stores...
Write a java application that will read a set of values from the user and stores them in array a[]. The application should ask the user for the number of values he will enter. You need to do the following methods: 1. Read: This method will read n values from the user and store them in an array a 2. Print: this method will print the array as given in the sample output 3. maxEven: This method will find the...
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 code that gets student test scores from the user. Each test score will...
Write a java code that gets student test scores from the user. Each test score will be an integer in the range 0 to 100. Input will end when the user enters -1 as the input value. After all score have been read, display the number of students who took the test, the minimum score, the maximum score, the average score (with decimal point, and the number of A where an A is a score in the range 90-100.
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()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT