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

  Class that stores information about a report

Create a class that stores information about a report containing multiple currency transactions in multiple currencies. This includes the name of the report and each of the transactions that occurred.

  The program reads in names

Write a program and include the following methods. The program reads in names and ages (use 2 parallel arrays, maximum size 50) from a file called Stuff.dat.

  Write a version of sumpairs

Write a version of sumPairs  that sums each component of the pairs separately, returning a pair consisting of the sum of the first components and the sum of the second components. So basically [(3,1)(10,3)] would return (13,4).

  Write a recursive program

Write a recursive program to compute the number of ways in which an integer k can be written as sum

  Implement simple java program to input syllabus grades

To implement simple Java program to input (hypothetical) syllabus grades, computing and displaying both normal Mean and Harmonic Mean.

  Write a java program to register students for a college

Project is for designing and developing a College Registration program. Write a Java program to register students for a college

  Socket programming in java: tcp

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

  Calculate the maximum data rate in mb/second

b)How much cylinder skew is needed for an Oceangate disk operating at 20,000 rpm(new series for the Christmas promotions) which has a seek time of 0.5 milliseconds? This disk has 800 sectors of 512 bytes each on each track.

  Dangerousmonster which inherits the monster

An interface - DangerousMonster which inherits the Monster interface and has a method called destroy() with void return type.(Note: Just like a class can inherit from another class, an interface can inherit from another interface using the "extends..

  Design an object-oriented java application

You are to design an object-oriented Java application to let the user play a dice game that uses two dices. The player bets on a value and the dices roll

  Create a java class called samearraysexception

Create a Java class called SameArraysException that extends the Exception class.

  Write a java program called salesinfominer

Write a Java program called SalesInfoMiner that reads in a file of products, stored in text format. The program must then read in information about past sales transactions and output all the products to a new file, sorted by product description,..

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