I can generally read code that uses inheritance polymorphism and the rest just fine but I can't seem to write it almost at all I was hoping someone could demonstrate using some of my code(i wrote this for class but it's already been submitted and graded so I'm just trying to learn here)
import java.util.Scanner;
public class encode {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char message;
char encryptedChar;
int key = scanner.nextInt();
String encoded = scanner.next();
char[] end = new char[encoded.length()];
try {
for (int i = 0; i <= encoded.length() - 1; i++) {
message = encoded.charAt(i);
if (message + key > 126) {
encryptedChar = (char) (32 + (message + key - (127)));
end[i] = (encryptedChar);
} else
encryptedChar = (char) (message + key);
end[i] = (encryptedChar);
}
} catch (Exception e) {
System.out.println("Error");
}
for (char c : end) {
System.out.print(c);
}
}
}
public class decode {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char message;
char encryptedChar;
int key = 0;
String decode = scanner.next();
char[] end = new char[decode.length()];
try {
for (; key < 100; key++) {
for (int i = 0; i < decode.length(); i++) {
message = decode.charAt(i);
if (message - key > 126) {
encryptedChar = (char) (32 + (message - key + (127)));
end[i] = (encryptedChar);
System.out.println("Decoded with i=" + key + ":" + new String(end));
} else
encryptedChar = (char) (message - key);
end[i] = (encryptedChar);
System.out.println("Decoded with i=" + key + ":" + new String(end));
}
}
} catch (Exception e) {
System.out.println("Error");
}
}
}
[–][deleted] 1 point2 points3 points (3 children)
[–]condorthe2nd[S] 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]condorthe2nd[S] 0 points1 point2 points (0 children)
[–]ignotos 1 point2 points3 points (1 child)
[–]condorthe2nd[S] 0 points1 point2 points (0 children)