Import Java Scanner Import Java Arraylist Import Java File Import Java Printwrit
import java.util.Scanner;import java.util.ArrayList;import java.io.File;import java.io.PrintWriter;public class task1{ public static void main(String[] args) {check_primes(“in1.txt”, “out1.txt”);System.out.printf(“Exiting…n”); }}
This is an incomplete program. The goal of the program is to:
- Read a file that contains integers.
- Determine if each of those integers is a prime or not.
Complete that program, by defining acheck_primesfunction, that satisfies the following specs:
- Functioncheck_primestakes two arguments, calledin_file, out_file. Argumentin_filespecifies the name of the input file, that contains the integers to be processed. Argumentout_filespecifies the name of the output file, where the results will be saved.
- Ifin_filecannot be opened for reading, the function should print on the screen “Error in opening file for reading” and return.
- Ifout_filecannot be opened for writing, the function should print on the screen “Error in opening file for writing” and return.
- Otherwise, if both in_file and out_file can be opened: for each integer X stored in in_file, the function writes to out_file a line stating either “X is prime” or “X is not prime”.
IMPORTANT: You are NOT allowed to modify in any way the main function.
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
