Question

1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line,...

1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line, for equality. Print any lines that are not equivalent indicating the line numbers in both files. The language of implementation is java

2 . Create a program that reads a string input from the user, then determines and prints how many of each lowercase vowels (a, e. i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also count and print the number of non-vowel characters.

Homework Answers

Answer #1

/*
 *  Java Program for comparing two files
 */


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
 
public class Main
{   
  public static void main(String[] args) throws IOException
  {
    String fileName1 = "file1.txt";
    String fileName2 = "file2.txt";

    BufferedReader reader1 = new BufferedReader(new FileReader(fileName1));
    BufferedReader reader2 = new BufferedReader(new FileReader(fileName2));
      
    String line1 = reader1.readLine();
    String line2 = reader2.readLine();
    
    boolean areEqual = true;
    int lineNum = 1;
      
    while (line1 != null || line2 != null)
    {
      if(line1 == null || line2 == null)
      {
        areEqual = false;
        break;
      }
      else if(! line1.equalsIgnoreCase(line2))
      {
        areEqual = false;
        break;
      }
      line1 = reader1.readLine();
      line2 = reader2.readLine();
      lineNum++;
    }

    //  ignoring end of file line
    lineNum--;
  
    if(areEqual)
    {
      System.out.println("The number of lines: " + lineNum);
      System.out.println("Two files have the same content.");
    }
    else
    {
      System.out.println("Two files have different content. They differ at line " + lineNum);
    }

    reader1.close();
    reader2.close();
  }
}

Note: For queries, drop me a comment.

Know the answer?
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
Similar Questions
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
#include <stdio.h> #define K   1024 /** (2pts) * Make a program that reads a line of...
#include <stdio.h> #define K   1024 /** (2pts) * Make a program that reads a line of input (up to 1024 characters, using * fgets,) and scans the input for the lowercase letter 'x'. If it finds an x, * it should print "The string has an x in it.\n" and exit, if it does not, it * should print "The string did not have an x in it.\n", then exit. You may * not use any standard library functions other...
Write an assembly program that reads characters from standard input until the “end of file” is...
Write an assembly program that reads characters from standard input until the “end of file” is reached. The input provided to the program contains A, C, T, and G characters. The file also may have new line characters (ASCII code 10 decimal), which should be skipped/ignored. The program then must print the count for each character. You can assume (in this whole assignment) that the input doe not contain any other kinds of characters.  the X86 assembly program that simply counts...
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
(PLEASE USE C++) (PLEASE USE THE EXAMPLE GIVEN) Question 1: [10 pointes] the input file inFile.txt...
(PLEASE USE C++) (PLEASE USE THE EXAMPLE GIVEN) Question 1: [10 pointes] the input file inFile.txt stores a number of words with possible replication. Each word is stored on a separate line. The number of words within inFile.txt is stored as the first line in that file. Write and test a program that reads the words from inFile.txt and prints them in outFile.txt  without replication as well as the number of replication for each word. Hint: to implement the above program,...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
You've been hired by Text Turtles to write a C++ console application that determines the reading...
You've been hired by Text Turtles to write a C++ console application that determines the reading grade level of the text in a file. The text comes from two files: SampleText1.txt and SampleText2.txt. Sample text1= It has often been said there's so much to be read you never can cram all those words in your head. So the writer who breeds more words than he needs is making a chore for the reader who reads. That's why my belief is...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT