1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Kitty [74]
3 years ago
7

Write a program that reads a file name from the keyboard. The file contains integers, each on a 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. If the input file does not exist, give an appropriate error message and terminate the program. After integers are stored in an array, your program should call the following methods in order, output the intermediate results and count statistics on screen, and at end output even integers and odd integers to two different files called even.out and odd.out.
Implement the following methods in the program:
* public static int[] inputData() – This method will ask user for a file name, create an array, and store the integers read from the file into the array. If input file does not exist, give an appropriate error message and terminate the program.
* public static void printArray(int[] array) – This method will display the content of the array on screen. Print 10 integers per line and use printf method to align columns of numbers.
public static void reverseArray(int[] array) – This method will reverse the elements of the array so that the 1st element becomes the last, the 2nd element becomes the 2nd to the last, and so on.
* public static int sum(int[] array) – This method should compute and return the sum of all elements in the array.
* public static double average(int[] array) – This method should compute and return the average of all elements in the array.
* public static int max(int[] array) – This method should find and return the largest value in the array.
* public static int min(int[] array) – This method should find and return the smallest value in the array.
* public static void ascendingSelectionSortArray(int[] array) – This method will use Selection Sort to sort (in ascending order) the elements of the array so that the 1st element becomes the smallest, the 2nd element becomes the 2nd smallest, and so on.
* public static void desendingBubbleSortArray(int[] array) – This method will Bubble Sort to sort (in descending order) the elements of the array so that the 1st element becomes the largest, the 2nd element becomes the 2nd largest, and so on.
* public static void outputData(int[] array) – This method will create two output files called even.out and odd.out. Scan through the entire array, if an element is even, print it to even.out. If it is odd, print the element to odd.out.
Computers and Technology
1 answer:
Sindrei [870]3 years ago
4 0

Answer:

Explanation:

import java.util.Scanner;

import java.io.*;

public class ArrayProcessing

{

public static void main(String[] args) throws IOException

{

Scanner kb = new Scanner(System.in);

String fileName;

System.out.print("Enter input filename: ");

fileName = kb.nextLine();

File file = new File(fileName);

if(!file.exists())

{

System.out.println("There is no input file called : " + fileName);

return;

}

int[] numbers = inputData(file);

printArray(numbers);

}

public static int[] inputData(File file) throws IOException

{

Scanner inputFile = new Scanner(file);

int index = 1;

int size = inputFile.nextInt();

int[] values = new int[size];

while(inputFile.hasNextInt() && index < values.length)

{

values[index] = inputFile.nextInt();

index++;

}

inputFile.close();

return values;

}

public static void printArray(int[] array)

{

int count = 1;

for (int ndx = 1; ndx < array.length; ndx++)

{

System.out.printf("%5.f\n", array[ndx]);

count++;

}

if(count == 10)

System.out.println("");

}

}

You might be interested in
Transition words and phrase in a paragraph
balandron [24]

Answer:

Msms

Explanation:

8 0
3 years ago
Read 2 more answers
After you divide the viewfinder appropriately you locate the subject? PLZ ANSWER MY TEST DO BY TONIGHT
Sloan [31]
The Answer is A: <span>along one of the division lines. </span>
4 0
3 years ago
Direct messages are the only private forms of communication on Twitter. True False
Sunny_sXe [5.5K]
True but ill keep typing so it meets twenty charecters                                              

7 0
3 years ago
The process of a web server adding a tcp header to a web page, followed by adding an ip header, and then a data link header and
kumpel [21]
<span>Encapsulation is defined as the process of adding a header in front of data supplied by a higher layer (and possibly adding a trailer as well).</span>
7 0
3 years ago
Which one of the following commands will list the contents of a directory, and put those listed contents into a file called "myd
9966 [12]

Answer:

ls -pla > mydir

Explanation:

ls is the command to list the contents of the directory.

-p option indicate / as the designator for directories

-l  options enables line by line entries for files

-a option lists all files including special files starting with .

> is used for redirecting the output of the ls command to the specified file.

So ls -pla > mydir will run ls command with -pla option and populate the file mydir with the contents of the result.

5 0
3 years ago
Other questions:
  • On sites that use "cloud computing," how is your information being stored?
    13·1 answer
  • You want to boot a linux system into singer user mode/ what options might you add to a linux kernel options list in a boot loade
    9·1 answer
  • According to the Doppler effect, objects moving away from Earth would have a
    12·2 answers
  • What is work flexibility?
    15·1 answer
  • failure of the _ cylinder will often result in sudden unexpected loss of the ability to stop the vehicle
    10·1 answer
  • Who is a data base administrator
    12·1 answer
  • What privacy risks do new technologies present,<br> and how do we decide if they're worth it?
    11·1 answer
  • Why is it difficult to convince top management to commit funds to develop and implement SIS
    5·2 answers
  • Use the syntax SELECT ________ (expression) [Column Name] to limit the result set to the number of rows defined by the expressio
    10·1 answer
  • What are the value and data type (float, int, bool, or str) of this expression:<br> 5 // 2
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!