Question

i have to write a program that asks the names of 2 files. the first should...

i have to write a program that asks the names of 2 files. the first should be open for reading second for writing. the program should read the the contents of the first file change all characters to uppercase and store in the second file. the second file will be a copy of the first file, except that all characters will be uppercase. use notepad to test the program. i got this so far {
        String firstfile;
        String secondfile;
       
    Scanner keyboard;
            keyboard = new Scanner (System.in);
           
    System.out.println("Enter the first file name");
    firstfile = keyboard.nextLine();
   
    File readfile = new File(firstfile);
    Scanner inputFile = new Scanner(readfile);
   
    System.out.println("Enter second file name");
    secondfile = keyboard.nextLine();
    PrintWriter outputFile = new PrintWriter(secondfile);
      while (inputFile.hasNext())
      {
          String line = inputFile.nextLine();
          outputFile.println(line.toUpperCase());
         
      }
      inputFile.close();
      outputFile.close();
        }

how do i use note pad to test this poem

Frankie owned a
ferocious feline named
Freddy as a pet.
Freddy was funny and
furry.
His fur is bright red
with black stripes.

thanks

                                                                                                                                                                                                                                           

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.io.*;
public class Test{
   public static void main(String args[]) throws Exception
   {
       String firstfile;
       String secondfile;
      
       Scanner keyboard;
       keyboard = new Scanner (System.in);
      
       System.out.println("Enter the first file name");
       firstfile = keyboard.nextLine();
      
       File readfile = new File(firstfile);
       Scanner inputFile = new Scanner(readfile);
      
       System.out.println("Enter second file name");
       secondfile = keyboard.nextLine();
       PrintWriter outputFile = new PrintWriter(secondfile);
       while (inputFile.hasNext())
       {
           String line = inputFile.nextLine();
           outputFile.println(line.toUpperCase());
          
       }
       inputFile.close();
       outputFile.close();
   }
}

/* run the program as followed

C:\Users\A nariaRa\Desktop〉javac Test.java C:AUsersAmarlaRa \Desktop>java Test Enter the first file name a.txt Enter second f

Now open b.txt in notepad to check the contents of the file.

FRANKIE OWNED A
FEROCIOUS FELINE NAMED
FREDDY AS A PET.
FREDDY WAS FUNNY AND
FURRY.
HIS FUR IS BRIGHT RED
WITH BLACK STRIPES.

*/

Add a comment
Know the answer?
Add Answer to:
i have to write a program that asks the names of 2 files. the first should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the...

    Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the names of two files. The first file should be opened 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 uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters will be uppercase. Use...

  • Fibtester: package fibtester; // Imported to open files import java.io.File; // Imported to use the exception...

    Fibtester: package fibtester; // Imported to open files import java.io.File; // Imported to use the exception when files are not found import java.io.FileNotFoundException; // Imported to write to a file import java.io.PrintWriter; // Imported to use the functionality of Array List import java.util.ArrayList; // Imported to use the exceptions for integer values import java.util.NoSuchElementException; // Imported to use when the array is out of bounds import java.lang.NullPointerException; // Imported to take input from the user import java.util.Scanner; public class FibTester...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • Problem: Use the code I have provided to start writing a program that accepts a large...

    Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...

  • Create a program via Java that has atleast 8 characters long, one upper case, and one...

    Create a program via Java that has atleast 8 characters long, one upper case, and one lower case, and one digit. here is my code:     public static void main(String[] args)     {         //variables defined         String passwords;         char password =0;                 //settings up password condition to false         boolean passwordcondition= false;         boolean size=false;         boolean digit=false;         boolean upper=false;         boolean lower=false;         //inputting a scanner into the system         Scanner keyboard = new Scanner(System.in);...

  • Select the correct answer. (1)     Which of the following will open a file named MyFile.txt and...

    Select the correct answer. (1)     Which of the following will open a file named MyFile.txt and allow you to read data from it?                (a)      File file = new File("MyFile.txt");           (b)      FileWriter inputFile = new FileWriter();           (c)       File file = new File("MyFile.txt");                      FileReader inputFile = new FileReader(file);           (d)      FileWriter inputFile = new FileWriter("MyFile.txt"); (2)     How many times will the following do - while loop be executed?                      int x = 11;             do {             x...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • I have a program that reads a file and then creates objects from the contents of...

    I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...

  • I need help with my computer science 2 lab. First I am asked to run the...

    I need help with my computer science 2 lab. First I am asked to run the following program and check output? public static void main(String []args) { String filename= "output.txt"; File file = new File(fileName);    try{ FileWriter fileWriter = new FileWriter(file, true); fileWriter.write("CS2: we finished the lecuter\n"); fileWriter.close(); }catch (Exception e){ system.out.println("your message"+e); } String inputfileName = "output.text"; File fileToRead = new File (inputfileName); try { Scanner = new Scanner (fileToread); while(Scanner.hasNextLine()){ String line = scanner.nextLine(); system.out.println(line); } }catch(Eception...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT