2. Write a program to read two lists of names from two input files and then match the names in the two lists using Co-sequential Match based on a single loop. Output the names common to both the lists to an output file,
In Java
Thanks for the question, When you run the program please ensure you update the input file names and output file name in the commented section below ======================================================================= import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class CoSequentialMatch { public static void main(String[] args) { // first file path and name String firstFile = "names.txt"; // second file path and name String secondFile = "names_ (2).txt"; ArrayList<String> firstFileNames = getNamesFromFile(firstFile); ArrayList<String> secondFileNames = getNamesFromFile(secondFile); int minSize = firstFileNames.size() < secondFileNames.size() ? firstFileNames.size() : secondFileNames.size(); // output file path and name String outputFile = "common-names.txt"; try { FileWriter writer = new FileWriter(new File(outputFile)); for (int i = 0; i < minSize; i++) { if (firstFileNames.get(i).equalsIgnoreCase(secondFileNames.get(i))) { writer.write(firstFileNames.get(i) + "\r\n"); } } writer.close(); System.out.println(outputFile+" generated successfully."); } catch (IOException e) { System.out.println("Error: Uanble to open/write data to file: " + outputFile); System.exit(1); } } private static ArrayList<String> getNamesFromFile(String fileName) { ArrayList<String> data = new ArrayList<>(); try { Scanner scanner = new Scanner(new File(fileName)); while (scanner.hasNextLine()) { data.add(scanner.nextLine()); } scanner.close(); } catch (FileNotFoundException e) { System.out.println("Error: Unable to find/read file: " + fileName); System.exit(1); } return data; } }
===============================================================
2. Write a program to read two lists of names from two input files and then...
Write a python program that prompts the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the scripts should simply output “Yes”. If they are not, the program should output “No”, followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a...
2.12 LAB 2.3: File I/O - CSV update This program shouldget names of input and output files from command line (NOT from user input)read in integers from a csv (comma-separated values) file into a vectorcompute the integer average of all of the valuesconvert each value in the vector to the difference between the original value and the averagewrite the new values into a csv file
java Program Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt
java Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
Please don't use a void fuction and this is a c++ question. Thanks Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...
in Java and also follow rubric please 4. Write a complete program to do the following: Using an input and output files, write a program that will read 20 numbers from an input file called InFile. Sum all even numbers and multiply all odd numbers. Print the numbers read from the input file to an output file called OutFile. Also print the sum of the even numbers and the product of the odd numbers to the output file. Rubric: •...