JAVA QUESTION
Design a simple calculator for two numbers.
Important note. Avoid using IDE's facilities for automatically GUI code generation.
Simple Calculator Second Number Multiply 」L Divide First Number Result Add Subtract Power Remainder -
Below code for calculator using Java AWT import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; class Calculator extends JFrame implements ActionListener { private static final int FRAME_WIDTH = 300; private static final int FRAME_HEIGHT = 220; private static final int FRAME_X = 150; private static final int FRAME_Y = 100; private JPanel buttonPanel; private JPanel inputOutputPanel; private JTextField info; private boolean editable = true; public Calculator() { Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(4,4,5,5)); buttonPanel.setBorder(new EmptyBorder(10,10,10,10)); inputOutputPanel = new JPanel(); inputOutputPanel.setLayout(new FlowLayout()); inputOutputPanel.setBorder(new EmptyBorder(10,10,10,10)); setTitle("Calculator using Java"); setSize(FRAME_WIDTH,FRAME_HEIGHT); setResizable(false); setLocation(FRAME_X,FRAME_Y); info = new JTextField(); info.setFont(new Font("SansSerif", Font.PLAIN, 16)); info.setBackground(Color.white); info.setBorder(BorderFactory.createLineBorder(Color.black)); info.setPreferredSize(new Dimension(270, 35)); info.addActionListener(this); inputOutputPanel.add(info); contentPane.add(inputOutputPanel); String buttons[] = {"7", "8", "9", "/", "4", "5", "6", "*", "1", "2","3","-","0",".","=", "+",}; for (String i : buttons) { JButton button = new JButton(i); button.addActionListener(this); buttonPanel.add(button); } contentPane.add(buttonPanel); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent event) { if (event.getSource() instanceof JButton) { JButton clickedButton = (JButton) event.getSource(); if(clickedButton.getText().equals("=")) { addOutput(); } else { addInput(clickedButton.getText()); } } else { addOutput(); } } public void addInput(String line) { if(editable) { info.setText(info.getText()+line); } else { info.setText(line); editable = true; } } public void addOutput() { double output = 0; try { ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName("JavaScript"); info.setText(engine.eval(info.getText()).toString()); } catch(ScriptException e) { info.setText("Syntax error"); } editable = false; } public static void main (String [] args) { Calculator calculator = new Calculator(); calculator.setVisible(true); } }
Could you code this question on Matlab? :) Question: Design a GUI based application, named Calculator, which perform basic arithmetic operations ie., add, subtract, multiply, and divide Your design must have 1) Two separate input fields for reading the two operands (let's say a and b) 2) 4 Four button (labeled as +, -, *, /) to let the user select an operation. 3) An output field for displaying the result Following table shows operations performed on pushing each of...
Create a simple calculator. Your interface should contain two input boxes in which the user can put two numbers. There should be four buttons: add, subtract, multiply, and divide. When the user inputs two number and clicks on an operation button, the result should be displayed in the label. Can some please help my code that i came up with just displays a pop box with no words or nothing! I'm not the best at coding. Any tips or advice...
Task 6: Write a Java program to make a calculator. The calculator should add, subtract, multiply and divide the numbers inserted by the user. Feel free to add more operations to your calculator, such as power, sqrt etc. (Hint: Use Switch)
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 calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...
Write MIPS code that emulates a simple calculator. The calculator initially has the value 0. Prompt the user to enter a command. A command is a number, where 0 is add, 1 is subtract, 2 is multiply, 3 is divide, 4 is clear, and 5 is exit. When the user enters 0, 1, 2, or 3, prompt the user for a number to add, subtract, multiply or divide from the current value. If the user enters 4, then clear the...
IN PYTHON! Create a calculator GUI. The GUI should let the user add, subtract, multiply, and divide two numbers they input. All user input and the result displayed to the user should be seen in the GUI itself (i.e. the terminal should not show anything). Thank you very much! PLEASE PASTE IN HERE THE RIGHT INDENTS
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...
7- (50 points) Write a simple calculator in Python which supports four basic mathematical operators (1.e. + - / *). You need to define a module which supports addition, deletion, multiplication and subtraction. Then import your module to your calculator file and use it in your code. The following example shows how your basic calculator needs to work. Select operation: 1.Add 2.Subtract 3.Multiply 4.Divide Enter your choice(1/2/3/4): 3 Enter first number: 12 Enter second number: 14 12 * 14 =...
SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){ int num1,num2; cout << "Enter two numbers "<< endl; cout << "First :"; cin >> num1; cout << "Second :"; cin >>num2; int result=num1+num2; cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result; ...