Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in the file called data.in that contains integers, ea

ID: 3622135 • Letter: W

Question

Write a program that reads in the file called data.in that contains integers, each on separate line. The first line of the input file will contain the number of integers in the file. You then create a corresponding array and fill the array with integers from the remaining lines. After integers are storing in an array, your program should call the following methods in order at end output even integers and odd integers to two different files called even.out and odd.out

Methods:
public static int [] inputData()
public static void reverseArray(int [] array)
public static void printArray(int [] array)
public static int sum(int [] array)
public static double average(int [] array)
public static int max(int [] array)
public static int min(int [] array)
public static void outputData(int[] array)

So far this is what my program looks like:

import java.io.*;

public class ArrayProcessing
{
   public static int[] inputData()throws IOException
   {
      File data = new File("data.in");
      Scanner inputFile = new Scanner(data);
      if(!data.exists())
      {
         System.out.println("ERROR: File does not exist");
         System.exit(0);
      }
   
      int [] array = new int[10];
   }
   }
   public static void reverseArray(int[]array)
   {
      int[]j = new int[array.length()];
      for(int i=0; i<array.length-i; i++)
      {
         j[i] = array[(array.length()-1)-i];
      }
   }
   }
   public static void printArray(int[]array)
   {
      int j=0;
  
      for(j=0; j<array.length; j++)
      {
         System.out.println(array[j]);
      }
   }
   }
   public static int sum(int[]array)
   {
      int j;
      int sum = 0;

      for(j=0; j<array.length; j++)
      {
         sum = sum + array[j];
      }
      System.out.println("The sum of all elements: " + sum);
   }
   }
   public static double average(int[]array)
   {
      double sum = 0;
      int j;
      double average = 0;

      for(j=0; j<array.length; j++)
      {
         sum = sum + array[j];
         average = sum/array.length;
      }
      System.out.println("The average of all elements: " + average);
   }
   public static int max(int[]array)
   {
      double max = array[0];
      for(int j = 0; j<array.length; j++)
      {
         if(array[j]>max)
            max = array[j];
      }
      System.out.println("max = " + max);
   }
   public static int min(int[]array)
   {
      double min = array[0];
      for(int j = 0; j<array.length; j++)
      {
         if(array[j]<min)
            min = array[j];
      }
      System.out.println("min = " + min);
   }
   public static void outputData(int[]array)
   {



Explanation / Answer

please rate - thanks

import java.io.*;
import java.util.*;
public class ArrayProcessing
{    static int n;
    public static void main(String[] args)throws FileNotFoundException,IOException

        { File data = new File("data.in");
      Scanner input = new Scanner(data);
        if(!data.exists())
      {
         System.out.println("ERROR: File does not exist");
         System.exit(0);
      }
      n=input.nextInt();
      int [] array = new int[n];
        array=inputData(input);
        reverseArray(array);
        printArray(array);
        System.out.println("The sum of all elements: " + sum(array));
        System.out.println("The average of all elements: " + average(array));
      System.out.println("max = " + max(array));
        System.out.println("min = " + min(array));
        outputData(array);
        }
   public static int[] inputData(Scanner input)throws IOException
   {int [] array = new int[n];
    for(int i=0;i<array.length;i++)
        array[i]=input.nextInt();
    return array;
    }
    
   public static void reverseArray(int array[])
   {int i,j;
    int temp;
    for(i=0;i<array.length/2;i++)
        {temp=array[i];
        array[i]=array[array.length-1-i];
        array[array.length-1-i]=temp;
       }
   }

   public static void printArray(int[]array)
   {
      int j=0;

      for(j=0; j<array.length; j++)
      {
         System.out.println(array[j]);
      }
   }

   public static int sum(int[]array)
   {
      int j;
      int sum = 0;

      for(j=0; j<array.length; j++)
      {
         sum = sum + array[j];
      }
      return sum;
   }
  
   public static double average(int[]array)
   {
      double sum = 0;
      int j;
      double average = 0;

      for(j=0; j<array.length; j++)
      {
         sum = sum + array[j];
         average = sum/array.length;
      }
        return average;
         }
   public static int max(int[]array)
   {
      int max = array[0];
      for(int j = 0; j<array.length; j++)
      {
         if(array[j]>max)
            max = array[j];
      }
   return max;
   }
   public static int min(int[]array)
   {
      int min = array[0];
      for(int j = 0; j<array.length; j++)
      {
         if(array[j]<min)
            min = array[j];
      }
    return min;
   }
   public static void outputData(int array[])throws FileNotFoundException,IOException
   {PrintStream odd=new PrintStream(new File("odd.out"));
    PrintStream even=new PrintStream(new File("even.out"));
    int i;
    for(i=0;i<array.length;i++)
          if(array[i]%2==0)
                  even.println(array[i]);
            else
                  odd.println(array[i]);

    }
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote