Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

pseudocode. only Lab 9-4: Writing Methods that Return a Value In this lab, you c

ID: 3575574 • Letter: P

Question

pseudocode. only Lab 9-4: Writing Methods that Return a Value

In this lab, you complete a partially written Java program that includes a method that returns a value. The program is a simple calculator that prompts the user for two numbers and an operator ( +, , *, /, or % ). The two numbers and the operator are passed to the method where the appropriate arithmetic operation is performed. The result is then returned to the main() method where the arithmetic operation and result are displayed. For example, if the user enters 3, 4, and *, the following is displayed:

3.00 * 4.00 = 12.00

students will design the logic for an application and submit a partially completed Java program and the pseudocode.
In this assignment, students will design the logic for the program that prompts the user for two numbers and an operator (+, -, *, /, or %). The two numbers and the operator are passed to the method where the appropriate arithmetic operation is performed. The result is then returned to the main() method where the arithmetic operation and result are displayed.

// Calculator.java - This program performs arithmetic, ( +. -, *. /, % ) on two numbers
// Input: Interactive.
// Output: Result of arithmetic operation

import javax.swing.*;

public class Calculator
{
public static void main(String args[])
{
  double numberOne, numberTwo;             
  String numberOneString, numberTwoString;
  String operation;
  double result;
      
  numberOneString = JOptionPane.showInputDialog("Enter the first number: ");
  numberOne = Double.parseDouble(numberOneString);
  numberTwoString = JOptionPane.showInputDialog("Enter the second number: ");
  numberTwo = Double.parseDouble(numberTwoString);
  operation = JOptionPane.showInputDialog("Enter an operator (+.-.*,/,%): ");
  
  // Call performOperation method here  
  

  System.out.format("%.2f",numberOne);
  System.out.print(" " + operation + " ");
  System.out.format("%.2f", numberTwo);
  System.out.print(" = ");
  System.out.format("%.2f", result);

  System.exit(0);

} // End of main() method.


// Write performOperation method here.

} // End of Calculator class

.pseudocode. only needed

Explanation / Answer

//Pseudo Code For Basic Calculator

Import statements

Class Calculator{
   public static main()
       double numberA, numberB
       String operatorS
       double numResult

       print "Welcome to the Calculator Program"
       print "(+)Addition"
       print "(-)Subtraction"
       print "(*)Multiplication"
       print "(/)Division"
       print "(%)Mode"
       print "(Q)Quit
       print "Please enter 1st number: "
       input numberA
       print "Please enter operation you desired: "
       input operatorS
       print "Please enter 2nd number: "
       input numberB
       numResult = performOperation(numberA, numberB, operatorS)
       print "You entered, " numberA " " operatorSym " " numberB " = "numResult"."      
       end Main
      

   public static double performOperation(double numberA, double numberB, String operatorS)
       //You can use either Switch case or Nested If/else
       double result      
       if operatorS = + then
           Result = numberA + numberB
       else if operatorS = - then
           Result = numberA – numberB
       else if operatorS = * then
           Result = numberA * numberB
       else if operatorS = / and numberB = 0 then
           print "You cannot divide by 0, please enter another number "
           input numberB
       else if operatorS = / then
           Result = numberA / numberB
       else if operatorS = % then
           Result = numberA % numberB

       endif
       endif
       endif
       endif
       endif
       endif

       return Result
       end performOperation
endClass