Create a flowchart for this Java Program

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create a flowchart for this Java Program

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.JOptionPane;

public class Calculator extends Frame implements ActionListener {
Label fn, sn, op;
TextField tf1, tf2, tf3;
Button c;
Calculator() {
fn = new Label("First Number:");
fn.setBounds(60, 70, 110, 20);
sn = new Label("Second Number:");
sn.setBounds(60, 100, 110, 20);
op = new Label("Operator:");
op.setBounds(60, 130, 110, 20);
tf1 = new TextField();
tf1.setBounds(180, 70, 150, 20);
tf2 = new TextField();
tf2.setBounds(180, 100, 150, 20);
tf3 = new TextField();
tf3.setBounds(180, 130, 150, 20);
c = new Button("Compute");
c.setBounds(173, 170, 163, 30);
c.addActionListener(this);
add(fn);add(sn);add(op);add(tf1);add(tf2);add(tf3);add(c);
setSize(400, 250);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try {
double n1 = Double.parseDouble(tf1.getText());
double n2 = Double.parseDouble(tf2.getText());
double r;
char ch = tf3.getText().charAt(0);
switch (ch) {
case '+':
r = n1 + n2;
JOptionPane.showMessageDialog(null, "The sum is: " + r);
break;
case '-':
r = n1 - n2;
JOptionPane.showMessageDialog(null, "The difference is: " + r);
break;
case '*':
r = n1 * n2;
JOptionPane.showMessageDialog(null, "The product is: " + r);
break;
case '/':
r = n1 / n2;
JOptionPane.showMessageDialog(null, "The quotient is: " + r);
break;
default:
JOptionPane.showMessageDialog(null, "Invalid Operator");
break;
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex);
}
}

public static void main(String[] args) {
new Calculator();
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education