The following program coding needed: Create a simple program that takes two numb
ID: 3648709 • Letter: T
Question
The following program coding needed:Create a simple program that takes two numbers as input and, when the user clicks on a button, adds the numbers together. If the user clicks on the "Single" button, the values will add as Single; i.e., each value should be considered of type Single. Likewise, if the user clicks the "Double" button, the program will add values as Double. Each button should have a separate output.
Do not use the Val( ) function in this coding exercise. Also, to the general declarations section of your code, add these two code lines: Option Strict On and Option Explicit On.
Guideline:
-The window should open in the center of the screen.
-While your text doesn
Explanation / Answer
import java.awt.Graphics; import javax.swing.*; public class AddApplet extends JApplet { int sum; int x; int y; public void init() { String num1; String num2; // read first number from the keyboard num1 = JOptionPane.showInputDialog("Enter a First number"); // read seond number from the ketboard num2 = JOptionPane.showInputDialog("Enter a Second number"); x= Integer.parseInt(num1); // comvert the string to an integer y= Integer.parseInt(num2); // convert the string to an integer sum = x + y; } public void paint(Graphics g) { //writes the output in the applet starting at position 30, 30 g.drawString("The sum of x ("+x+") +y ("+y+")="+sum, 30,30); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.