Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

import java.Scanner; import java.ArrayList; import java.File; import java.PrintWriter; public class task1 { public static void main(String args) {...

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:

  1. Read a file that contains integers.
  2. 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.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question