Total: 3 points. None of the ciphers are implemented, class properties and methods placed inside classes incorrectly and non-functionally, no tests.
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);
}
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(){
}
}
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() {
}
}
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.
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!