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
2. Name the three building blocks of design that pertain to form.
inna [77]

Answer:

Point, Line, Shape,Form, Color, Value, and Texture.

Explanation:

The elements of design, are the building blocks used by the designers to create the designs. ...

Point, Line, Shape,Form, Color, Value, and Texture.

3 0
3 years ago
A wet-carpet cleaner that carries it's own water supply has water pressure created by a.
QveST [7]
The correct answer of the given question above would be option D. A wet-carpet cleaner that carries it's own water supply has water pressure created by a MOTOR-DRIVE PUMP. T<span>his product is easy to use, strong, and highly durable. Hope this answers your question. Have a great day!</span>
8 0
3 years ago
Read 2 more answers
This graph shows both a reflection and a
Tpy6a [65]

Answer:

y=-3x-×-1 I think it's answer is it

6 0
3 years ago
Read 2 more answers
In animation what is exaggerated to make the characters more intensely what they are​
aleksklad [387]

Answer:

Exaggerated used of the technique can produce a comical effect, while more realistic animation must time the actions exactly to produce a convincing result. Slow in and slow out. Adds more frames near the beginning and near the end of a movement, and fewer in the middle, to make the animation appear more realistic.

5 0
3 years ago
A key or combination of keys that complete an action more efficiently than using the mouse is called a(n) keyboard shortcut.
andreev551 [17]
The answer to your question is true
6 0
2 years ago
Other questions:
  • An attribute whose value uniquely identifies an object is called a(n) _______.​
    15·1 answer
  • Search engines enable you to
    13·2 answers
  • Serveral cheetas are growling at each other while hunting for animals.for which need are they competing?
    14·1 answer
  • A simple operating system supports only a single directory but allows it to have arbitrarily many files with arbitrarily long fi
    13·1 answer
  • In order to install a device, the operating system needs the required __________ for that device.
    13·2 answers
  • Which amendment to the Constitution ended slavery in the United States?
    8·1 answer
  • Consider the following program segment: //include statement(s) //using namespace statement int main() { //variable declaration /
    9·1 answer
  • Kathy created a video presentation of her company, which will be shown on a television show as an advertisement. Her company wan
    11·1 answer
  • What is sampling?
    6·1 answer
  • How do cyber criminals target user’s end devices?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!