Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NOTE: I NEED HELP WITH THIS WITHOUT IMPORTING JAVA.IO. ALL I CAN IMPORT IS JAVA SCANNER FOR INPUTS. Java Write a program to evaluate a

NOTE: I NEED HELP WITH THIS WITHOUT IMPORTING JAVA.IO. ALL I CAN IMPORT IS JAVA SCANNER FOR INPUTS.

Java

Write a program to evaluate a mathematical expression as it is entered by the user. Here, the user will enter alternating numbers and operators, terminating with a .. You are required to keep a running evaluated result for the expression and finally print the output when the user is done. Each type of operation needs to have its own method. The expression will only consist of integers and you only need to account for the 5 basic integer math operations ( +, -, *, / and %). Make sure your program conforms to the following requirements:

1. Write 5 methods, one for each basic arithmetic operators. They take 2 parameters each and return a result.

2. In the main method, read a number and a character alternatively until you encounter a ..

3. Keep a running result variable, where you store the result of the calculation so far.

4. Once the user is done entering the expression, print out the result.

5. You can assume all the numbers are integer.

6. Make sure to call the functions to do the calculations. Dont do the calculations in main().

7. You can assume that the input will be as expected. You dont need to do any error checking here.

8. You can ignore operator precedence. Just evaluate expressions as they come in.

There are 2 sample runs here:

Enter the expression:

1

+

26

*

2

%

19

/

5

.

The result is 3

I need this by only using import.java.util.Scanner; I'm stuck due to all the guidelines that were given to me.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

What are the logistics implications of internationalisation?

Answered: 1 week ago