-2

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();
    }
}

}
12
  • 3
    A capital C is different from a lower case c. Did you try both? Commented Dec 4, 2017 at 5:01
  • All Java identifiers are case-sensitive. Caesar and caesar are not the same identifier. Commented Dec 4, 2017 at 5:03
  • Right, sorry that was a typo, and using both uppercase and lowercase provide the same error. Here's a screenshot of exactly what's going on: gyazo.com/a39a5793fced9fc67b22abb22317957c Commented Dec 4, 2017 at 5:08
  • 1
    post your full code here Commented Dec 4, 2017 at 5:18
  • 1
    Is there a package declaration at the top of Caesar.java? Commented Dec 4, 2017 at 5:19

2 Answers 2

0

First of all javac Caesar.java should say file not found...

Your Caaesar class is part of the caaesar package.

The fully qualified class name is caaesar.Caaesar, which is how you run this class

Sign up to request clarification or add additional context in comments.

Comments

0

If your professor intends to run

java Caesar input.txt output.txt

then you need all of the following. Spelling is important, and so is whether each letter is upper or lower case.

  • Your code file must be called Caesar.java,
  • The class in your code file must be called Caesar,
  • The class in your code file must contain a method that starts with public static void main(String[].
  • There must be no package declaration at the top of the file.

Please try to meet all these conditions, and be fastidious about the details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.