Write a program that reads a file name from the keyboard

Assignment Help JAVA Programming
Reference no: EM13164836

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 main program should call the following methods in order, output the intermediate results 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, int counter) - This method will display the content of the array on screen. The second parameter counter is to make sure that you only process the array elements that contain valid data items. Print 10 integers per line and use printf method to align columns of numbers.

 

public static int outOfOrder(int[] array) - This method will test the array for being out of order. The method returns -1 if the elements are not out of order; otherwise, it returns the index of the first element of the array that is out of order. For example, consider                     a = {1, 2, 3, 2, 4, 7, 5, 8, 9, 1}, a[2] and a[3] are the first pair out of order, and a[3] is the first element out of order, so the method returns 3. If the array were sorted, the method would return -1.

 

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 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 selectionSort (int[] array) - This method should implement Selection Sort and sort the array of integers into descending order.

 

Public static int deleteRepeats (int[] array) - This method should delete all repeated integers from the sorted array. When an integer is deleted, the remaining integers are moved one position to fill in the gap. This will create empty positions at the end of the array, so the method should return the value that represents the actual number of array positions used.

 

For the array

 

4 4 3 3 3 2 2 1 1 1 1 -1 -12 -12 -12 -12

 

After this method is executed, the array will be

 

4 3 2 1 -1 -12

 

public static void outputData(int[] array, int counter) - This method will create two output files called even.out and odd.out. Scan through valid data items in the array, if an element is even, print it to even.out. If it is odd, print the element to odd.out.

 

 

Reference no: EM13164836

Questions Cloud

Write balanced half-reactions and the overall spontaneous : A voltaic cell is constructed with an Ag/Ag+ half-cell and a Pb/Pb2+ half-cell. Measurement shows that the silver electrode is positive. Write balanced half-reactions and the overall spontaneous reaction.
Show the propagation and transmission delay calculations : How long does it take a packet of length 1,000 bytes to propagate over a link of distance 3,000 km, propagation speed 3 *10^8 m/s, and transmission rate 3 Mbps? Show the propagation and transmission delay calculations.
Type of speech : To tell my audience about the life of florence nightingale is a specific purpose statement for what type of speech
What is a possible molecular formula of the hydrocarbon : What is a possible molecular formula of the hydrocarbon?
Write a program that reads a file name from the keyboard : 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 ..
What higher level did the electron reach : A ground-state H atom absorbs a photon of wavelength 94.91 nm, and its electron attains a higher energy level. The atom then emits two photons: one of wavelength 1281 nm to reach an intermediate level, and a second to return to the ground state.
Is it possible for an instruction to be receiving forwarding : Is it possible for an instruction to be receiving forwarding information and simultaneously being flushed?If possible, can you provide an example sequence of instructions?
Violent speech cross-criminal advocacy : When does violent speech cross the line from free expression into criminal advocacy?
Write a program with three radio buttons : Write a program with three radio buttons and circle. ( You can choose whether you draw the circle or if the circle is a label image.) When the user clicks on the first radio button

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd