0

I have been tasked with with creating a caesar cipher that has a main method, and has other methods named exactly how they want them within my project requirements.

I have been emailing my Teacher's assistant back and forth on this to get help but since I will say that we haven't been directly told anyway on how to properly shift the ASCII lettering so I've been trying to look around on google and here a bit and they have it set up to not use as many methods as I've been asked or it's in the C language.

My question as it stand is, for netbeans IDE 8.1 what is the proper code to get it to shift the .txt file.

If anyone asked I'll put up my rubric if it is asked of me.

package mcintosh_project3;
import java.io.File;
import java.util.Scanner;
/**
 *James McIntosh
 *Project 03
 */
public class McIntosh_Project3 
{
    public static void main(String[] args, int option) throws Exception
    {
      boolean run = true;
        File inputfile;
        if (option == 1)
        {
            Scanner input = new Scanner(System.in);
            System.out.println("What text file would you like to encrypt?");
            String inputFile = input.nextLine();              
        }
        if (option == 2)
        {
            Scanner input = new Scanner(System.in);
            System.out.println("What text file would you like to decrypt?");
            String inputFile = input.nextLine(); 
        }
        if (option == 3)
        {
            run = false;
        }
        if (option > 3)
        {
            System.out.println("Invalid option, please choose again.");    
        }

    } 
    public static int getMenuOption() throws Exception
    {
       int option;

        Scanner input = new Scanner(System.in); 
        System.out.println("1. Encrypt");
        System.out.println("2. Decrypt");
        System.out.println("3. Quit");
        System.out.println("What would you like to do?");
        option = input.nextInt();
        return option;
    }

    public static int key(File inputfile, int option) throws Exception
    {
          public static int key(File inputfile, int option) throws Exception
{

    char key = 'a';

    if (option == 1)
    {
        key += 5;
    }
    if (option == 2)
    {
        key -= 5;
    }
    return key;

}

public static void encrypt(File inputFile, int key, int option) throws Exception
{
    if (option == 1)
    {
        key += 5;
    }
    System.out.println(inputfile); //incorrect as of right now
}
public static void decrypt(File inputFile, int key, int option) throws Exception
{
    if (option == 2)
    {
        key -= 5;
    }
}

}

  • *"My question as it stand is, for netbeans IDE 8.1 what is the proper code to get it to shift the .txt file."* - Are you asking us to write that code for you? If not, what are you asking? – Stephen C Nov 13 '16 at 00:07
  • I don't really want the code written for me but I'm at a lost where most of the lines in my method named key are riddled with error lines and I'm not sure why If I'm running the returned variables through them. I'm just not sure what to do to make netbeans happy. – J.McIntosh Nov 13 '16 at 00:11
  • 1
    Well to be honest, your code contains so many basic Java errors that it looks like you got "left behind" a few weeks ago. You really need to have a long talk with your teacher / TA about how to address this. – Stephen C Nov 13 '16 at 00:49
  • For the record, StackOverflow is not a basic programming teaching / tutorial service. If you need that kind / level of help, then you are in the wrong place. (There are people here who will happily try to write code for you ... though we try to discourage this behavior, because it doesn't help in the long run. However, there are relatively few people here who know how to explain basic programming to newbies. And for those who do, the Q&A medium is not suitable for doing this.) – Stephen C Nov 13 '16 at 01:03
  • I apologize then, I was once referenced to this site by a TA last semester. – J.McIntosh Nov 13 '16 at 01:09
  • Your TA should not have done that. – Stephen C Nov 13 '16 at 01:34

1 Answers1

0

The errors you get are coming from these lines:

inputfile chara += 5;
inputfile chara -= 5;

It looks like what you are trying to do is something like what you can do with arrays, and get every chara from inputfile. That's not valid Java, though. If you want to read from a file, you'll want to use an InputStream. Check out an example here.

Hopefully that gets you started.

Community
  • 1
  • 1