Write an applet program that would enter two variables in a text field and perform the following operations when calculate button is pressed. Design a friendly interface. Have buttons for all operations including exit.
Addition
Subtraction
Multiplication
Division
Code:
====
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Q2 extends Applet implements ActionListener
{
TextField num1 = new TextField(10);
TextField num2 = new TextField(10);
TextField res = new TextField(10);
Label fir = new Label("FIRST NO:");
Label sec = new Label("SECOND NO:");
Label answer = new Label("Answer:");
Button a = new Button("Addition");
Button s = new Button("Subtraction");
Button m = new Button("Multiplication");
Button d = new Button("Division");
public void init()
{
num1.setForeground(Color.RED);
num2.setForeground(Color.RED);
add(fir);
add(num1);
add(sec);
add(num2);
add(res);
add(answer);
// add(sum);
// add(diff);
// add(mul);
// add(mul);
add(a);add(s);add(m);add(d);
a.addActionListener(this);
s.addActionListener(this);
m.addActionListener(this);
d.addActionListener(this);
}
public void paint(Graphics g) {
this.fir.setLocation(50,50);
this.num1.setLocation(150,50);
this.sec.setLocation(50,100);
this.num2.setLocation(150,100);
this.a.setLocation(20,150);
this.s.setLocation(100,150);
this.m.setLocation(200,150);
this.d.setLocation(300,150);
this.answer.setLocation(50, 200);
this.res.setLocation(150, 200);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == a)
{
int n1 = Integer.parseInt(num1.getText());
int n2 = Integer.parseInt(num2.getText());
res.setText(" " + (n1 + n2));
}
else if (e.getSource() == s)
{
int n1 = Integer.parseInt(num1.getText());
int n2 = Integer.parseInt(num2.getText());
res.setText(" " + (n1 - n2));
}
else if (e.getSource() == m)
{
int n1 = Integer.parseInt(num1.getText());
int n2 = Integer.parseInt(num2.getText());
res.setText(" " + (n1 * n2));
}
else if(e.getSource() == d)
{
int n1 = Integer.parseInt(num1.getText());
int n2 = Integer.parseInt(num2.getText());
res.setText(" " + (n1 / n2));
}
}
}
Output:
======
![Applet Viewer: Q2 Applet DL FIRST NO: SECOND NO: 2 Addition! Subtraction」 Mu ation] Division Answer: 12 Applet started.](http://img.homeworklib.com/questions/02d475a0-9756-11ea-90c1-7168f939d767.png?x-oss-process=image/resize,w_560)
Please comment if you need any help.
Write an applet program that would enter two variables in a text field and perform the...
Write a calculator program using JavaScript in HTML in the same HTML file. (There will only be 1 HTML file containing everything that you use for this program.) *************JavaScript Functions should be written in the HTML <head> .............. </head> tag, **************** (Please be mindful of the formatting of the text of your program. Meaning that do not copy paste everything in a single line. Add clear comments for a better understanding of your program) as follows Assignment: create a form...
Question 20: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210
Write a program that declares an initializes two variables a & b with the values your choice, use pointer to those variables and perform, addition, subtraction and multiplication: Print the results.
Calculator = 0.01 Calculate . Add O subtract O Multiply ODvide uttons on the right determine the operation that is performed on the numbers. For example, the following image shows values 12 and 3 are entered in the ion in selected. When the Calculate button is pressed, the result of the addition operation is shown after the equal sign ( In this example, the result is 1 Calculator 12 .15.01 Calculate | ⓔAdd subtract。Multiply O Divide g images show the...
This week we looked at an example math program that would display the answer to a random math problem. Enhance this assignment to prompt the user to enter the solution to the displayed problem. After the user has entered their answer, the program should display a message indicating if the answer is correct or incorrect. If the answer is incorrect, it should display the correct answer. The division section should use Real data types instead of Integer data types. Keep...
RAPTOR PROGRAMMING Write a program which will receive two integer values as input. Then prompt the user to choose one of the following operations and produce an output with the selected operation. 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division Example output with response: Please enter an input: 2 Please enter another input: 3 Please choose from the follow: 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division Output: 2 % 3 is 2.
A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction, multiplication and division) of two numbers, using your understanding of Java. Description: You need to write a program that will display a menu when it is run. The menu gives five choices of operation: addition, subtraction, multiplication, division, and a last choice to exit the program. It then prompts the user to make a choice of the calculation they want to do. Once the...
in mathlab Take two color images of same size Write the coding to perform the following operations Image addition Image subtraction Image multiplication Image division
Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...
Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...