Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Uppercase File Converter. Write a program that asks the user for the names of tw

ID: 3861322 • Letter: U

Question

Uppercase File Converter. Write a program that asks the user for the names of two files. The First file should be for reading and the second file should be opened for writing. The program should read the contents of the first file, change all characters to lowercase, and store the results in the second file. Assume the first file contains more than one line. The pseudo code is given below.

Open the input file.
      Open the output file.
      while (inFile.hasNext())
      {
         read a line from input file using inFile.nextLine();
         convert it to uppercase using toUppercase()method;
         write it to the output file using outFile.println(…….);
      }
      
      Close both files.

Input file input.txt example:

There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”
Albert Einstein

Output file:

THERE ARE ONLY TWO WAYS TO LIVE YOUR LIFE. ONE IS AS THOUGH NOTHING IS A MIRACLE. THE OTHER IS AS THOUGH EVERYTHING IS A MIRACLE.”
ALBERT EINSTEIN

Explanation / Answer

import java.io.*;

import java.util.*;

import java.io.PrintWriter;

import java.io.File;

public class HelloWorld{

public static void main(String[] args) throws IOException {

      Scanner sc=new Scanner(System.in);

      System.out.println("enter Input filename and output filename");

      String inputFile=sc.next();

      String outputFile=sc.next();

Scanner inFile = new Scanner (new File(inputFile));

//File file = new File ("result.txt");

PrintWriter outFile = new PrintWriter (outputFile);

int count = 0;

while (inFile.hasNext()) {

String word = inFile.next();

count++;

//System.out.println(word.toLowerCase());

outFile.print (word.toUpperCase());

outFile.print (" ");

}

outFile.close();

inFile.close();

//System.out.println("Number of words is " + count);

}

     }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote