QuestionQuestion

1. Write a program to open the input filename “input01.txt”. Read and display all integers (and integers only) in the file to the output file named “output01.txt”. Note that the file may contain something that is not an integer.

Example:
“input01.txt”10 a 12 15.4 13.2 16 7 4.9
“output01.txt”
10 12 16 7


2. Write a method to open an input file for reading double numbers and returning the average those numbers (MAX = 100 numbers). Name this method findAvgFromFile. This method takes the input filename as its parameter. Specify the method declaration and the caller to this method with the input filename “input02.txt”.

Example:
“input02.txt”
3.1 3.2 3.3
Then the call
double avg = findAvgFromFile(“input02.txt”);
should make avg have value 3.3;

3. Write a method to open an input file for reading double numbers and returning an array containing those numbers (MAX = 100 numbers). Name this method findArrFromFile.This method should take the input filename as its parameter, and should return an array containing the read numbers. Specify the method declaration and the caller to this method with the input filename “input03.txt”.
Example:
“input03.txt”
3.4 4.5 5.6 6.7
Then the call
double arrList = findArrFromFile(“input03.txt”);
should make arrList[0] = 3.4, arrList[1] = 4.5, arrList[2] = 5.6 and arrList[3]
= 6.7;


4. Write a method to open an input file for reading an integer N. Name this method readCapFromFile. This method should take the input filename as its parameter and should return the read integer. Write another method named writePrimeToFile taking into account the followings as parameters (1) an integer P and (2) the output filename (type String) fileName. This method will not return any value and will only write to the output file the prime number closest to (but not exceeding) P.
For example:
The call (i)
int N = readCapFromFile(“input04.txt”);
with file “input04.txt” contains the value 20 should make N having value 20. The call (ii) ( following (i) ) writePrimeToFile(N, “output04.txt”); // here N==20 from the call (i)should create the file “output04.txt” containing the number 17 (since 17 is the prime closet to but not exceeding 20)

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.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

public class Problem1 {

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException
{
Scanner input = new Scanner(new File("input01.txt"));
PrintWriter writer = new PrintWriter("output01.txt", "UTF-8");
String read;

while(input.hasNext())
{
read = input.next();
try
{
int test = Integer.parseInt(read);
writer.print(test + " ");
} catch(NumberFormatException e){}
}
writer.close();
input.close();
}
}...
$33.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