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

  Write a class named test scores

Write a class named TestScores.The class constructor should accept an array of test scores as an argument.The class should have a method that returns the average of the test scores.

  Design a course registration system

Create an application which represents a simplified course registration system using ArrayLists and HashMaps.

  Write java program which will permit user to input data

Write the Java Program which will permit the user to input data. The data will be validated using a loop that requires the user to input the data until it is correct or in the correct range. T

  Afterwards a way for the user to input

And so on and so forth then afterwards a way for the user to input that they finished a particular task on the list. After the user has input that they have finished a particular task the program should be print "Good Job!" or "Keep it up!"

  Write java program to evaluate postfix expressions

Write a java program to evaluate postfix expressions containing complex numbers using a stack. This program should contain two classes.

  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..

  Technical community blog

Write a blog article for a coding and technical community blog.

  Write java program to compute how much federal need to pay

Write a java application to calculate how much federal and state tax you need to pay. The program should accomplish the following task.

  Given a sequence of 10 integers

Write a program given that given a sequence of 10 integers, find out and delete the maximum and minimum number, then compute the average of the rest.

  Write a java program using array to auto-grade exams

Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C, D) for each student.

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  The menu is displayed and the user must select

The menu is displayed and the user must select an option (a number between 0 and 7). The action corresponding to the selection is performed, then the menu is displayed again and the user can choose another option.

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