QuestionQuestion

Your assignment is to write and test a Java program (Project5.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

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.

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.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

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");
    }
      
    /**
    * . display a dialog box containing the String parameter
    * . return the contents the user enters in the dialog box
    * @param message
    * @return
    */
    private static String getFileName (String message){

       String s = JOptionPane.showInputDialog(null, message);            
       return s;
    }...
$25.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats