0 Replies - 353 Views - Last Post: 08 April 2012 - 03:00 PM Rate Topic: -----

#1 Hngo4619  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-April 12

Programming Project - Compare two different text files using methods

Posted 08 April 2012 - 03:00 PM

Hello, I have a programming project that requires me to take a text file (let's call it Original.txt) and compare it to a modified version of the same text file (let's call it Diff.txt) and then Output another text file that displays the changes in the two files. I have to do this using methods (I've only started programming at the beginning of this year in an intro class) and a for loop, a while loop and a do-while loop. It's due on the 11th. I think I have the basic concept on what to do, but I don't have any clue on how to do it so I'm looking for a push in the right direction. Any help would be much appreciated. Here's what I have so far:


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

public class Project4 {
	
	/**
	 * @param args
	 */
	
	public static void main(String[] args) throws FileNotFoundException
	{
		Scanner inputFile = new Scanner(new File("./src/Original.txt"));
		Scanner diffFile = new Scanner(new File("./src/Diff.txt"));
		PrintWriter outputFile = new PrintWriter("./src/Output.txt");
		
		int i = Integer.parseInt(string);
	}
	
	private static int processCommand(Scanner inputFile, Scanner diffFile, PrintWriter outputFile)
	{
		int linecount = 0;
		
		return 0;
	}
	
	private static int processAddCommand(Scanner inputFile, Scanner diffFile, PrintWriter outputFile)
	{
		int currentIndex = 0;
		int inputIndexStart = 0;
		int inputIndexEnd = 0;
		int numberOfLines = 0;
		
		return 0;
	}
	
	private static int processDeleteCommand(Scanner inputFile, Scanner diffFile, PrintWriter outputFile)
	{
		int currentIndex = 0;
		int inputIndexStart = 0;
		int inputIndexEnd = 0;
		int numberOfLines = 0;
		
		return 0;
	}
	
	private static int processChangeCommand(Scanner inputFile, Scanner diffFile, PrintWriter outputFile)
	{
		int currentIndex = 0;
		int inputIndexStart = 0;
		int inputIndexEnd = 0;
		int numberOfLines = 0;
		
		return 0;
	}
	
}



My teacher also said that I should use these codes in my program somewhere:

int startIndex = 0, endIndex = 0, numberOfLines = 0;
char command = 'a';

diffFile.findInLine("(\\d+)(,(\\d+))?([acd])(\\d+)(,(\\d+))?");
MatchResult result = diffFile.match();



int endIndex, startIndex;
if (result.group(3) != null) // if there is a line number, interpret it
{
// transfer this String into an int
}
else
{
// Do something else that makes sense in your program
}



When she gave us the first code, she said that we shouldn't worry about what it actually means and simply find a way to implement it into our program.

Again, I think I know what the program should do, I just don't how to make the program do it. We also can't use arrays in this project, if that makes any difference. Any help would be much appreciated.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1