I have a complete Java program, but the way that my professor is going to check to make sure that the program is working correctly is through CMD using the command
"java Caesar input.txt output.txt"
But the issues I am running into are that when I compile using "javac Caesar.java
" it will compile and create a Caesar.class
file in the folder, but when I try run it as "java caesar input.txt output.txt
" it says Error: Could not find or load main class caesar
.
What am I doing wrong here?
I can provide additional information as needed.
package caaesar;
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
/**
*
* @author Connorbboggs
* Version 12.03.2017
*/
public class Caaesar
{
private static Scanner sc;
private static FileWriter fw;
private static BufferedWriter bw;
private Scanner inp;
private Scanner outp;
//DecodeChar class provided by you
public static char decodeChar(int n, char ch)
{
int ord;
if (ch >= 'A' && ch <= 'Z')
{
ord = ch - 'A';
ord += n;
ord %= 26;
return (char)(ord + 'A');
}
else if (ch >= 'a' && ch <= 'z')
{
ord = ch - 'a';
ord += n;
ord %= 26;
return (char)(ord + 'a');
}
else
{
return ch;
}
}
public static void main(String[] args)
{
//File input for decode.txt with the encrypted text
File inputFile = new File(args[0]);
//Output for the decrypted text
File outputFile = new File(args[1]);
try
{
//input from inputFile
sc = new Scanner(inputFile);
int shift = sc.nextInt();
String decoded = "";
//while lines are available text is fed to inputFile
while( sc.hasNextLine())
{
//Lines being fed into string line
String line = sc.nextLine();
//for loop to feed into decoded using decodeChar
for(int i=0; i<line.length(); i++)
{
decoded += decodeChar(shift, line.charAt(i));
}
decoded += '\n';
}
//Just to verify that the text is decrypted
System.out.println(decoded);
try
{
//create a fileWriter for outputFile
fw = new FileWriter(outputFile);
//write "decoded" to the file
fw.write(decoded);
//close the file
fw.close();
}
//exception catching
catch (IOException ex)
{
ex.printStackTrace();
}
}
//more exception
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}