Question: Write a code in Java. Your task is to read a file containing arithmetic instructions such as 3 + 4 4 - 10 7 *

Write a code in Java. Your task is to read a file containing arithmetic instructions such as

3 + 4 4 - 10 7 * 11 

Each instruction contains an integer, an operator (+, -, or *), and another integer.

Return an array list of the results. If there is any error, throw an IOException.

**Please do this without BufferedReader and ScriptManager. Only insert code in the bold area. Thank you!!

Complete the following code:

import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner;

public class Arithmetic { /** This class reads a file containing arithmetic expressions and returns an array list of the results. @param filename the file name @return a list of results */ public static ArrayList read(String filename) throws IOException { . . . //ONLY PUT CODE HERE } // This method checks your work. Do not touch it. public static String check(String filename) { try { return read(filename).toString(); } catch (IOException ex) { return "I/O exception thrown"; } catch (Exception ex) { return ex.getClass().getName(); } } }

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!