Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help as to why my java program will not run. also, wanted to double check the requirements for the assignment have been met.

i need help as to why my java program will not run. also, wanted to double check the requirements for the assignment have been met. attached are the program i wrote on my screen (first two) and the error message i am getting (third pic). then the rest of the pics following are the assignment and requirements....
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
2 1 import java.util.Scanner; 3 public class MiniCalculator2 { public static void main(String[] args) { 1 Scanner keyboard = new Scanner(System.in); System.out.println("Welcome to Mini Calculator"); System.out.println("I will calculate the value of expressions having"); System.out.println(" three operands and two operators."); System.out.println("The first operator must be either , /, or ."); System.out.println("The second operator can be +, -, 7, or 8."); 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 System.out.print("Enter first operand: "); double a=keyboard.nextDouble(); System.out.print("Enter first operator (*,/,!): "); char opl-keyboard.next().charAt(0); System.out.print("Enter second operand: "); double b-keyboard. nextDouble(); if (!(op1--. || opl-'/' || opl--'*')) { System.out.println("Error: First operand is invalid."); } else { System.out.print("Enter second operator (1,7,8): "); char op2-keyboard.next().charAt(0); I K MiniCalculator.java (Grasp 2) MiniCalculator 2.java 44 45 File Edit View Build Project Settings Tools Window Help XALODU *** 34 35 System.out.print("Enter second operator (1,2): "); 36 char op2=keyboard.next().charAt(0); 37 System.out.print("Enter third operand (../,?): "); 39 doublec-keyboard.nextDouble(); 40 41 if (!(op2--'+' || op2--'-' || op2-. || op2-/ || op2 =)) 42 43 System.out.println("Error: Second operand is invalid."); > olse 46 47 48 L 49 double result 0; 50 51 switch(op1) 52 { 53 case resultab; break; 54 cane '/' resultwa/bi break; 55 case ''t result atb; break; 56 ) 57 switch(op2) 58 59 case '': result-result.c; break; 11 result result/c; break; 61 case' result-resultic; break; +': result result+e; break; result-result-c; break; 1 64 ) 66 System.out.println("RESULT: "+a+*+op1+""+b+" **op2+" "+c+" - "+String.format("1.38".result)); 60 case 62 case 63 case 65 67 ) 68 >> 69 File Edit View Build Project Settings Tools Window Help & XB LED +* * 43 System.out.println("Error: Second operand is invalid."); 44 45 else 46 47 48 { 49 double result=0; 50 51 switch(opl) 53 case '*': result-a*b; break; 54 case '/' : result-a/b; break; 55 case 't': result-ab; break; 56 ) 57 switch(op2) 58 ( 59 case '*': result-result-c; break; 52 { El MiniCalculator java Grasp 2) MiniCalculator 2.java Compile Messages JGRASP Messages Run 1/0 Interactions Stop ----GRASP exec: javac - Minicalculator2.java Clear Minicalculator2.java:451 errors else without else Copy 1 error ---GRASP wedge: exit code for process is 1. ---GRASP: operation complete. A 20 Programming Assignment: Selection Module 3 - Mini Calc Always keep the following in mind: The textbook uses JOptionPane and System.exit often In this course we NEVER use either JOptionPane or System.exit. Using JOptionPane turns an app into a GUI (Graphical User Interface) app. To stop a GUI app properly System.exit is needed. System.exit can also be use inappropriately to stop a program at any point. To keep new programmers from misusing System.exit We DO NOT USE System.exit AT ALL. ALSO: Use ONLY ONE return statement per method. We DO NOT USE JOptionPane AT ALL because it slows down a program's input/output. 38 nd Selection Assignment This assignment is designed to give you experience in creating a Java application with sequence and selection statements. When writing this programs, only use sequence and selection statements. Do not use loops, other statements or any data types that have not been covered so far. If in doubt, contact your instructor REMEMBER: Programs that do NOT compile eam no more than 10% of their assigned point value. As you implement your solution consider which selection structure is best for your solution: an if-statement, an if-else statement or a switch statement. Each has its advantages in certain situations. Sometimes one is correct while another would be incorrect in certain situations Anytime the requirements dictate more than one input, always get the input from the user in the order given in the requirements. Every program written this semester MUST follow ALL the coding conventions for the course. If you have any questions on this assignment.--coding or requirements -- send me Canvas email Requirements for the Java application, MiniCalculator.java Write a Java application named, MiniCalculator.java, that calculates the result of evaluating an arithmetic expression containing three operands (type, double) and two operators. This program should begin by printing a welcome message with the title of the application (program) and a brief description of what it does (Note: this is NOT the same as the program prologue (https://earn.maricopa.edulcourses/1172368/pages/program-prologs- required. The prologue is a set of comments at the beginning of your source code meant for other Java programmers) This message and description displayed by the program are meant for the user of the program. Your message and description should be identical to the first five lines printed in every example execution of this program (see execution examples below) Next, the program must prompt the user for the expression. As you can see from the execution examples below, the program prompts for and reads each part of the expression before going to the next one. Therefore, there are five prompts and inputs, each on its own line (see examples below). The inputs must be promoted for and read in this order: 1. First operand 2. First operator (must be ", 1. or%) 3. Second operand 4. Second operator (+. - ./%) 5. Third operand This order is used in every execution example below. Use this order and word your prompts exactly as found in the example executions below. The user's input should be entered on the same line, at the end of the prompt text. This is done is every example below You should be prepared to use if-else and switch statements, as well as read user input using the Scanner's next and nextDouble methods. Do not use the Scanner's nextLine method. You may also find it helpful to use boolean flags. Input Validation As you can see from looking at the last two execution examples, your program should print an error message if the first operator is invalid, i.e., anything other than " (multiplication), (division), % (remainder). This error message would be displayed after reading the second operand. After printing this error message, the application should terminate this means that control should logically reach the end of the main method. Do NOT use a return or a System.exit to force the termination of the program. The other error that your program will check for is whether the second operator is valid. 20 . The second operator can be + (addition), - (subtraction). * (multiplication), / (division), or % (remainder). If the second operator is anything else, an error message as in the last execution example is displayed. After this, the application should terminate: this means that control should logically reach the end of the main method. Do NOT use a retum or a System.exit to force the termination of the program. Note: that checking for these errors and then skipping normal processing to reach the end of main is all done by structuring the i-else statements correctly. This makes our code easier to read/understand/debug and eliminates to need for extra returns and other poor programming practices. Ask questions if you have trouble with this concept. Execution/Testing Your program should produce the exact same results shown in the execution examples (if the inputs are the same). However, you should also test your program by entering other expression NOT used in the examples below. Your program should ALWAYS produce the correct result for any entered expression that meets the stipulations of these requirements. The resulting value must always be formatted to three decimal places (use printf or String.format). romano option NOTE: This program should ASSUME that all of the numeric operands entered are entered by the user without error. The program should not include input validation on the three operands. C The following execution examples show what your program should look like as it executes. Your program should format the resulting values EXACTLY as the shown in the examples by using printf or String.format. The wording of the introductory message, the prompts and all labels must be exactly as shown in these examples. The two operator errors must be handled exactly as indicated in the examples. If you have questions about the formatting, wording, etc., email your instructor RATHER THAN make an incorrect assumption. Note: The user's inputs are shown in highlighted bold characters. This is only done to help you understand the examples. Your program does NOT display anything in bold or highlighted First example execution: Welcome to Mini Calculator I will calculate the value of expressions having three operands and two operators. The first operator must be either *, I, or %. The second operator can be +, -, *, 1, or %. Enter first operand: 8 Enter first operator (*,/,%): * Enter second operand: 3 Enter second operator: Z Enter third operand: 6 RESULT: 8.0 * 3.0 / 6.0 = 4.000 Second example execution: Welcome to Mini Calculator I will calculate the value of expressions having three operands and two operators. The first operator must be either *, /, or %. The second operator can be +.-.. I. or. DO ols ae Input, Processing, Output Program Organization stes yeni When ever possible, strive to organize your program according to the IPO plan: Input, Processing, Output. This means that after declaring all of your variables, you have three sections of code: 1. Input Section: here you do all the prompting of the user and reading all of the required inputs storing each input in a variable. 2. Processing Section: in this section all calculations are done in the proper order and all results, both intermediate and final results, should be stored in variables. 3. Output Section: This section is the only section that outputs results. All results are output in this section. In fact, all required output (except for input prompts) is contained only in this section. Each section should begin with a single blank line, a brief comment stating the kind of section that is about to begin, and then all of the code for that section. This IPO organization cannot always be followed because the requirements may not allow this organization to work. HOWEVER, when IPO can be used, you should consider it a requirement to do so

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

Students also viewed these Databases questions