import java.io.*;
import java.util.*;
public class CodeDetection_comment
{
static final int maxCodeSize = 250;
public static void main (String[] args) throws
FileNotFoundException
{
int[] codeArray = new int[maxCodeSize];
int codeLength;
Scanner codeFile = new Scanner
(new FileReader("SecretCode.txt"));
PrintWriter outFile =
new PrintWriter("SecretCodeOut.txt");
codeLength = codeFile.nextInt();
if (codeLength <= maxCodeSize)
{
readCode(codeFile, codeArray, codeLength);
compareCode(codeFile, outFile, codeArray,
codeLength);
}
else
System.out.println("Length of the secret code "
+ "must be <= " + maxCodeSize);
codeFile.close();
outFile.close();
}
public static void readCode(Scanner inFile, int[] list,
int length)
{
int count;
for (count = 0; count < length; count++)
list[count] = inFile.nextInt();
}
public static void compareCode(Scanner inFile,
PrintWriter outP,
int[] list, int length)
{
int length2;
int digit;
boolean codeOk;
int count;
codeOk = true;
length2 = inFile.nextInt();
if (length != length2)
{
System.out.println("The original code and "
+ "its copy are not of "
+ "the same length.");
return;
}
outP.println("Code Digit Code Digit "
+ "Copy");
for (count = 0; count < length; count++)
{
digit = inFile.nextInt();
outP.printf("%5d %15d",
list[count], digit);
if (digit != list[count])
{
outP.println(" corresponding code "
+ "digits not the same");
codeOk = false;
}
else
outP.println();
}
if (codeOk)
outP.println("Message transmitted OK.");
else
outP.println("Error in transmission. "
+ "Retransmit!!");
}
}
And this is what i have so far(not much):
import java.io.*;
import java.util.*;
public class arrayhw
{
static final int maxCodeSize = 250;
public static void main (String[] args) throws
FileNotFoundException
{
Vector<float> codeVector = new Vector<float>();
int codeLength;
Scanner codeFile = new Scanner
(new FileReader("SecretCode.txt"));
PrintWriter outFile =
new PrintWriter("SecretCodeOut.txt");
codeLength = codeFile.nextInt();
if (codeLength <= maxCodeSize)
{
readCode(codeFile, codeVector, codeLength);
compareCode(codeFile, outFile, codeArray,
codeLength);
}
else
System.out.println("Length of the secret code "
+ "must be <= " + maxCodeSize);
codeFile.close();
outFile.close();
}
public static void readCode(Scanner inFile, ,
int length)
{
int count;
for (count = 0; count < length; count++)
list[count] = inFile.nextInt();
}
public static void compareCode(Scanner inFile,
PrintWriter outP,
int[] list, int length)
{
int length2;
int digit;
boolean codeOk;
int count;
codeOk = true;
length2 = inFile.nextInt();
if (length != length2)
{
System.out.println("The original code and "
+ "its copy are not of "
+ "the same length.");
return;
}
outP.println("Code Digit Code Digit "
+ "Copy");
for (count = 0; count < length; count++)
{
digit = inFile.nextInt();
outP.printf("%5d %15d",
list[count], digit);
if (digit != list[count])
{
outP.println(" corresponding code "
+ "digits not the same");
codeOk = false;
}
else
outP.println();
}
if (codeOk)
outP.println("Message transmitted OK.");
else
outP.println("Error in transmission. "
+ "Retransmit!!");
}
}
is this something that i can just change a few things around with? or am i going to have to rewrite a lot of this code?
the main things that are really hurting me are the method calls.... it uses some kind of array thing as parameters, and i'm just not really sure what that means or how i should replace it with a vector type thing...
sorry for posting so much code. any help would be immensely appreciated.

New Topic/Question
Reply




MultiQuote





|