Question: Write a Java Program that can read from a file and translate mathematical expressions line by line. All code must be written in the 'Main'

Write a Java Program that can read from a file and translate mathematical expressions line by line. All code must be written in the 'Main' method and you must not use Arrays or anything learned outside of class.
For each input line, you will print to the display:
"Result of Line [lineNumber]: [result]"
Result of line 1:3
Result of line 2:7
Result of line 3:13
You must use printf() for printing results.
"+" for addition
"-" for subtraction
"*" for multiplication
"/" for division
"+" to add to the result of the previous line to this line
"-" to subtract from the result of the previous line to this line
"*" to multiply the result of the previous line to this line
"/" to divide the previous line by the result
Result of Line 2: -4
Result of Line 3: Error: / by zero
Result of Line 4: 5
Result of Line 5: 160
Result of Line 6: No operator a ai 3
Result of Line 7: Non-integer input on this Line
[-"-jGRASP exec: java PolishMotationCalculator
Enter input file name: math3.txt
Result of Line 1: 2
Result of Line 2: 12
Result of Line 3: -1
Result of Line 4: 4
Result of Line 5: a
Result of Line 6: 3
Result of Line 7: 1
[ L--jgasp: operation complete.
[---jGRasp exec: java PolishwotationCalculator
Enter input file name: math4.txt
Result of Line 1: Non-integer input an this Line
Result of Line 2: 1
Result of Line 3: 1
Result of Line 4: Non-integer input on this Line
[.-jGRASP: operation complete.
...-jGRASP exec: java PolishNlotationCalculator
Enter input file nare: math5.txt
Resule of Line 1: 2
Result of Line 2: Non-integer input on this Line
Result of Line 3: -4
Result of line 4: Error: / by zero
Result of Line 5: -13
 Write a Java Program that can read from a file and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!