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
Which of the following is a trademark automatically received by an organization when a symbol is being consistently used in the
Mashcka [7]

Complete Question:

Which of the following is a trademark automatically received by an organization when a symbol is being consistently used in the normal course of business?

Group of answer choices

A. Open source trademark.

B. Common law trademark.

C. Registered trademark.

D. Open source trademark.

Answer:

B. Common law trademark.

Explanation:

A common law trademark can be defined as a protection or enforceable mark for a product name, logo, symbol or brand name used to distinguish goods and services prior to its registration with the state or federal government. Common law trademark is a trademark which is automatically received by an organization when a symbol is being consistently used in the normal course of business.

This ultimately implies that, common law trademarks are not governed by any statute and as such are only limited to the geographical location where they are used.

For instance, if a tomato paste is being sold to consumers with the product name "Ginoo" in Florida, the company's trademark applies to Florida only. Thus, another company can use the product name without any trademark infringement in other states of the country such as New York, Washington DC, California etc. except in Florida due to a common law trademark.

4 0
3 years ago
FOR ALL PLATO USERS:
aleksley [76]

You have to ask you teacher to show you which ones you got wrong and the answers to them.

6 0
3 years ago
Read 2 more answers
Write a program that records high-score data for a fictitious game. the program will ask the user to enter five names, and five
Harman [31]

Scores.cpp

#include <iostream>

#include <string>

using namespace std;

void initializeArrays(string names[], int scores[], int size);

void sortData(string names[], int scores[], int size);

void displayData(const string names[], const int scores[], int size);

int main()

{

   string names[5];

   int scores[5];

   //reading names and scores

   initializeArrays(names, scores, 5);

   //sorting the lists based on score.

   sortData(names, scores, 5);

   //displaying the contents of both arrays

   displayData(names, scores, 5);

 

  return 0;

}

void initializeArrays(string names[], int scores[], int size){

   for(int i=0; i<size; i++){

       cout<<"Enter the name for score #"<<(i+1)<<": ";

       cin >> names[i];

       cout<<"Enter the score for score #"<<(i+1)<<": ";

       cin >> scores[i];

       }

}

void sortData(string names[], int scores[], int size){

   

       int temp = 0;

       string tempStr = "";

       

       for(int i=0; i < size; i++){

               for(int j=1; j < (size-i); j++){

                      //checking max score and sorting based on it.

                       if(scores[j-1]< scores[j]){

                               //swap the elements!

                           //swapping scores

                               temp = scores[j-1];

                               scores[j-1] = scores[j];

                               scores[j]=temp;

                               

                               //swapping names

                               tempStr = names[j-1];

                               names[j-1] = names[j];

                               names[j]=tempStr;

                       }

                       

               }

       }

}

void displayData(const string names[], const int scores[], int size){

   cout<<"Top Scorers:"<<endl;

       //printing the elements up to the size of both arrays.

       for(int i=0; i<size; i++){

           cout<<names[i]<<": "<<scores[i]<<endl;

       }

}

3 0
3 years ago
Accepted identifier for a variable in PHP except:
Svetradugi [14.3K]

Answer:

b. & Puihaha

Explanation:

PHP variables are supposed to start with a $ sign.

Other rules followed by PHP variables are:

Starting character in variable name (after $) must be letter or _.

Other characters in variable names can be letters,numbers or _.

a. $_Puihaha

c. $Pui_haha

d. $Puihaha

satisfy these rules.

Whereas , b. & Puihaha does not satisfy as it starts with '&'. Moreover it also contains an invalid space character in the variable.

7 0
2 years ago
What does this translate to?: 01001001 01110011 00100000 01100010 01110010 01100001 01101001 01101110 01101100 01111001 00100000
Anastasy [175]
"Is Brainly down?" would be the text translation
7 0
3 years ago
Other questions:
  • Cameron wants to impress the owner of the company. He creates a graph that shows the improved productivity at the company over t
    13·2 answers
  • How can public-key encryption be used to distribute a secret key?
    6·1 answer
  • If num is an int which expression always evaluates to true if num holds an odd number
    14·1 answer
  • What type of maintenance can prevent the computer from breaking?
    11·2 answers
  • When using a presentation software you can change the size of the text to...? Increase Font size, Decrease font size, increase t
    15·2 answers
  • Where in the Formula tab on the ribbon would you find the Use in Formula function?
    11·2 answers
  • Advantages of Linux include_____.
    6·1 answer
  • Which pair of devices have the same input motion and different outputs?
    15·1 answer
  • The type value ____ for the input element may cause modern browsers to validate entries to ensure that they are valid web addres
    14·1 answer
  • What Does The Computer Monitor Contain?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!