Skip to content

Instantly share code, notes, and snippets.

@geluso
Last active July 18, 2018 19:48
Show Gist options
  • Save geluso/4be867e1e239283581804bd377eebdc4 to your computer and use it in GitHub Desktop.
Save geluso/4be867e1e239283581804bd377eebdc4 to your computer and use it in GitHub Desktop.
05-cipher-grading A

Total: 3 points. None of the ciphers are implemented, class properties and methods placed inside classes incorrectly and non-functionally, no tests.

InaccessibleObjectException

Hm, I've never seen InaccessibleObjectException before. Where did you get the idea to use this? Also, I don't see anything inside the try block that would possible cause an exception. Checking an int with == and printing things are basically impossible to fail.

I looked it up and it looks like a Java 9 thing. You'll have to show me how it works on your machine.

Excellent variable name for hunh.

int codeChoice = Integer.parseInt(answer);
try {
    if (codeChoice == 1) {
        System.out.println("Your choice: 1 encode");
    } else if (codeChoice == 2) {
        System.out.println("Your choice: 2 decode");
    }
} catch (InaccessibleObjectException e) {
    System.err.println("Inaccessible Object Exception." + e.getMessage());
    System.out.println(hunh);
}

Class Properties

You tried to declare the ALPHABET inside the Cipher constructor. You should delcare it near the top of the file, just under the class declaration.

Don't put it here:

public class Cipher {
  public Cipher(){
    public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
  }
}

Put it here:

public class Cipher {
  public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";

  public Cipher(){
  }
}

Class Methods

You declared class methods inside the class Constructor. Java can't ever do methods inside methods.

Incorrect:

public class Cipher {
  public Cipher(){
    public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";

    public String encode(String payload){

    }
    public String decode(String payload){
    }
    protected String replaceCharacters (String payload, String source, String target){
    }
  }
}

Everything in Java is at this level of indentation:

class SomeClass {
  public static final String PROPERTY_FOR_OTHER_CLASSES = "ABCDEF";

  public int someClassProperty;
  public int anotherClassProperty;

  public SomeClass() {
    System.out.println("This is the constructor");
  }

  public int otherMethod() {

  }

  public int yetAnotherMethod() {

  }

  public String toString() {

  }
}

Useful Classes vs Main

You're trying to define a main method inside the Cipher class. The main method should only be in the Main.java file for this lab. The Cipher class defines objects to be used in the main program. The Main.java file defines what the main program is. There's a separation between creating objects that will be used, and writing a program that uses them.

@MavenOfCode
Copy link

Thanks so much for this feedback, Steve. I finally understood the nested methods thing being wrong I think on Monday in lecture and really cemented in my mind yesterday. I'll be working on resubmitting this and hopefully, all I've learned will show!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment