Hello! I am trying to debug this assigment. I already find some bugs and fixed them, however; I am stuck and struggling with the rest. I would appreciate a hint and explanation to continue. Thank you.      import java.util.*; // for scanner public class Calc { public static void main(String[] args) { boolean done = false; Scanner console = new Scanner (System.in); while (!done){ displayMenu(); selection = getUserSelection(console); done = processSelection(selection, console); } System.out.println("Thank you for using this program.  Goodbye."); }   private static boolean processSelection(String selection, Scanner console) { boolean done = false; if (!selection.equalsIgnoreCase("E")){ if (selection.equalsIgnoreCase("U")){ calculateResults(console); } else if (selection.equalsIgnoreCase("H")){ //No need to write a Help Menu at this time, but logic and program execution // should still operate normally and display original menu after message prints System.out.print("Help Menu is under construction, " + "hence not available at this time."); } else { System.out.println("Incorrect entry...please try again!"); } } else { done = true; } return done; }   private static void calculateResults(Scanner console) { //displayCalculatorInstructions(); double operand1 = console.nextDouble(); char operator = console.next().charAt(0); double operand2 = console.nextDouble(); double result = 0.0; boolean isOperatorValid = true; if (operator == '+'){ result = operand1 + operand2; } else if (operator == '-'){ result = operand1 - operand2; } else if (operator == '*'){ result = operand1 + operand2; } else if (operator == '/'){ if (operand2 != 0.0){ result = operand1/operand2; } else { result = Double.NaN; //Returns Not a Number } } else if (operator == '^'){ result = Math.pow(operand2, operand1); } else { isOperatorValid = false; } if (isOperatorValid){ System.out.println(operand1 +" "+operator+""+operand2+" = " + result); //One could also use printf to control the precision of result, but not necessary now. } }   private static void displayCalculatorInstructions() { System.out.println("Enter a mathematical expression to evaluate."); System.out.println("Valid operations are: +, -, /, *, ^ (for exponents)."); System.out.println("Input expression using spaces between the operands (numbers) " + "and the operator, followed by Enter."); System.out.println("Here is the valid format:"); System.out.println("\t "); System.out.print("Your expression: "); }   //The method header for getUserSelection has no errors. private static String getUserSelection(Scanner console) { String selection = console.nextInt(); return selection; }   private static void displayMenu() { System.out.println("Enter one these options:"); System.out.println("\tH for Help"); System.out.println("\tC for using calculator"); System.out.println("\tE for exiting this program"); System.out.print("Your selection: "); }   }

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

Hello! I am trying to debug this assigment. I already find some bugs and fixed them, however; I am stuck and struggling with the rest. I would appreciate a hint and explanation to continue. Thank you. 

 

 

import java.util.*; // for scanner

public class Calc {

public static void main(String[] args) {

boolean done = false;

Scanner console = new Scanner (System.in);

while (!done){

displayMenu();

selection = getUserSelection(console);

done = processSelection(selection, console);

}

System.out.println("Thank you for using this program.  Goodbye.");

}

 

private static boolean processSelection(String selection, Scanner console) {

boolean done = false;

if (!selection.equalsIgnoreCase("E")){

if (selection.equalsIgnoreCase("U")){

calculateResults(console);

}

else if (selection.equalsIgnoreCase("H")){

//No need to write a Help Menu at this time, but logic and program execution

// should still operate normally and display original menu after message prints

System.out.print("Help Menu is under construction, "

+ "hence not available at this time.");

}

else {

System.out.println("Incorrect entry...please try again!");

}

}

else {

done = true;

}

return done;

}

 

private static void calculateResults(Scanner console) {

//displayCalculatorInstructions();

double operand1 = console.nextDouble();

char operator = console.next().charAt(0);

double operand2 = console.nextDouble();

double result = 0.0;

boolean isOperatorValid = true;

if (operator == '+'){

result = operand1 + operand2;

}

else if (operator == '-'){

result = operand1 - operand2;

}

else if (operator == '*'){

result = operand1 + operand2;

}

else if (operator == '/'){

if (operand2 != 0.0){

result = operand1/operand2;

}

else {

result = Double.NaN; //Returns Not a Number

}

}

else if (operator == '^'){

result = Math.pow(operand2, operand1);

}

else {

isOperatorValid = false;

}

if (isOperatorValid){

System.out.println(operand1 +" "+operator+""+operand2+" = " + result);

//One could also use printf to control the precision of result, but not necessary now.

}

}

 

private static void displayCalculatorInstructions() {

System.out.println("Enter a mathematical expression to evaluate.");

System.out.println("Valid operations are: +, -, /, *, ^ (for exponents).");

System.out.println("Input expression using spaces between the operands (numbers) "

+ "and the operator, followed by Enter.");

System.out.println("Here is the valid format:");

System.out.println("\t<operand1> <space> <operator> <space> <operand2> <Enter>");

System.out.print("Your expression: ");

}

 

//The method header for getUserSelection has no errors.

private static String getUserSelection(Scanner console) {

String selection = console.nextInt();

return selection;

}

 

private static void displayMenu() {

System.out.println("Enter one these options:");

System.out.println("\tH for Help");

System.out.println("\tC for using calculator");

System.out.println("\tE for exiting this program");

System.out.print("Your selection: ");

}

 

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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