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

  Give at least one constructor without any parameter

We learned as popular Set implementation. Write own TreeSet class that implements following interface: You are to give at least one constructor without any parameter.

  Solving programming problems

Write a computer program that will figure out the total of an order when given the amount of the order ($1000) and a sales tax rate of eight percent.

  Create a web application for sheridan restaurant

Create a web application for Sheridan Restaurant Reviews that contains the following functionality - Display a table of all restaurants based on the city entered by the user

  Write a recursive method to reverse a string.

write a recursive method to reverse a string. Explain why you would not normally use recursion to solve this problem?

  Recognize one high severity vulnerability for computer

Recognize one high severity vulnerability for each computer (if there is one). Explain vulnerability and describe control(s) to minimize risk from vulnerability.

  Java program to decide whether integer is perfect number

For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a Java program that decides whether integer is a perfect number.

  Write a program to register students for a college

Students have names, addresses and courses. Implement the interface class RegisterStudent. RegisterStudent has one method, public boolean register, which returns the boolean value of true or false if the student is successfully registered for the ..

  Write down java program for furniture company

Write down a Java program for the furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate price of table manufactured with chosen wood.

  Allows the user to enter students names followed

Write a program that allows the user to enter students names followed by their test scores and outputs the following information(assume that the maximum nmber of students in the class is 50

  Method that receives an array and returns with no duplicate

Write a program that contrains a method that receives an array and returns a new array with no duplicates.

  Dijikstra for undirected graph using simple scheme

Dijikstra for undirected graph using simple scheme with array and fibonacci heap and compare the performance/results, preferably in java.

  Application named arithmeticmethods

Create an application named ArithmeticMethods whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayNumberPlus10()

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