Your assignment is to write and test a Java program (Project8.java) that will
- Vpqnrqhwk
- Rating : 40
- Grade : A+
- Questions : 2
- Solutions : 1079
- Blog : 0
- Earned : $19352.58
complete solution correct answer key
Your assignment is to write and test a Java program (Project8.java) that will
1. read from an input text file
2. write to an output text file
3. use an integer array
4. use dialog boxes
Required main function: Here is the main method. Do not change it. import java.util.Scanner; import javax.swing.JOptionPane; import java.io.*; public class Project5 { public static void main (String [] args) throws FileNotFoundException final int LIMIT = 25; int [] numbers = new int [LIMIT]; int count = getInput(numbers); System.out.println (count + " values were read"); print (numbers, count); // prints original list sort (numbers, count); print (numbers, count); // prints sorted list System.out.println ("Program complete"); }
Required methods: You must write the following methods as specified to complete your program. Pay attention to the name, return type and parameters.
1. getFileName (String) : String
This method is called from the other two methods you will write. It has one parameter (a String) and returns a String. The method must do the following:
a. display a dialog box containing the String parameter
b. return the contents the user enters in the dialog box
For example, if the String “Enter input file name” is the parameter, this is displayed.
The method should then return the String entered by the user. Using a dialog box is covered in Lab 7.
2. getInput (int []) : int
This method has one parameter – the array of integers and returns an integer. It must:
a. call the getFileName method passing in the string “Enter input file name”
b. open the input text file with that name
c. read the integers from the file and store them into the array
d. return the count of how many values are read
e. close the file
The array has a limited size so it is important to count the input and make sure that the array does not overflow. A while loop is the solution for this. Here is the logic for this method. Get input file name by calling the getFileName method Open the file and create a Scanner for the file Initialize count to 0 While there are integers to read from the file and the array is not full Read an integer and store it into the array Increment count End while Close the file Return the count
3. print (int [], int) This method has two parameters – the array to print and the count of how many integers are in the array. There is no return value. The method must:
a. call the getFileName method passing in the string “Enter output file name”
b. open the output text file with that name
c. print the integers to the file from the first to the last
d. close the file
4. sort (int [], int) This method has two parameters – the array and the count of how many integers are in the array. There is no return value. The method must sort the array into ascending order using the selection sort algorithm as covered in lecture.
Documentation: Use Javadoc style for all comments.
1. Document the beginning of the file with your name and program number as well as a description of the program.
2. Document each method. Submit your file Project5.java using the link on Blackboard
[Solved] Your assignment is to write and test a Java program (Project8.java) that will
- This solution is not purchased yet.
- Submitted On 21 Jul, 2015 09:38:14
- Vpqnrqhwk
- Rating : 40
- Grade : A+
- Questions : 2
- Solutions : 1079
- Blog : 0
- Earned : $19352.58