I'm also having trouble on dividing the code into methods. This is my work done so far and net beans give me a lot of errors. Help!
package caesarcipher;
import textio.TextIO;
/**
*
* @author
*/
public class CaesarCipher {
enum code {encodeText, decodeText };
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String code;
char x;
int totalcount = 0;
while(true){
TextIO.put("Type in an E to encode a message or a D to decode a
message "
+ "or an X to exit the program: ");
code = TextIO.getlnWord();
switch(code.toUpperCase()){
case "E":
TextIO.putln("You have chosen to encode a message!");
break;
case "D":
TextIO.putln("You have chosen to decode a message!");
break;
case "X":
TextIO.putln("Bye!");
return;
}
}
}
static String encodeText(String code){
switch(code){
TextIO.put("Enter a shift count: ");
int shift = TextIO.getlnInt();
TextIO.put("Enter your plain text: ");
char[] message =
TextIO.getln().toUpperCase().toCharArray();
for(int i=0; i < message.length; i++){
char alpha;
if((message[i] >= 'A' && message[i] <= 'Z')){
int cryp =((int)message[i] + (shift));
if(cryp > (int) 'Z'){
cryp -= 26;
}
alpha = ((char)cryp);
}
else {
alpha = message[i];
}
System.out.print(alpha);
}
System.out.print("\n");
break;
}
}
static String decodeText()
switch(code){
TextIO.put("Enter a shift count: ");
shift = TextIO.getlnInt();
TextIO.put("Enter the encrypted message: ");
char[] dcode = TextIO.getln().toUpperCase().toCharArray();
for(int i=0; i< dcode.length;i++){
char alpha;
if((dcode[i] >= 'A' && dcode[i] <= 'Z')){
int cryp =((int)dcode[i]) - shift;
if(cryp < (int)'A'){
cryp += 26;
}
alpha = ((char)cryp);
} else {
alpha = dcode[i];
}
System.out.print(alpha);
}
System.out.print("\n");
break;
}
}
}
package caesarcipher;
import textio.TextIO;
/**
*
* @author
*/
public class CaesarCipher {
enum code {
encodeText, decodeText
};
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
String code;
char x;
int totalcount = 0;
while (true) {
TextIO.put(
"Type in an E to encode a message or a D to decode a message " + "or an X to exit the program: ");
code = TextIO.getlnWord();
switch (code.toUpperCase()) {
case "E":
TextIO.putln("You have chosen to encode a message!");
break;
case "D":
TextIO.putln("You have chosen to decode a message!");
break;
case "X":
TextIO.putln("Bye!");
return;
}
}
}
static void encodeText(String code) {
TextIO.put("Enter a shift count: ");
int shift = TextIO.getlnInt();
TextIO.put("Enter your plain text: ");
char[] message = TextIO.getln().toUpperCase().toCharArray();
for (int i = 0; i < message.length; i++) {
char alpha;
if ((message[i] >= 'A' && message[i] <= 'Z')) {
int cryp = ((int) message[i] + (shift));
if (cryp > (int) 'Z') {
cryp -= 26;
}
alpha = ((char) cryp);
} else {
alpha = message[i];
}
System.out.print(alpha);
}
System.out.print("\n");
}
public static void decodeText() {
TextIO.put("Enter a shift count: ");
int shift = TextIO.getlnInt();
TextIO.put("Enter the encrypted message: ");
char[] dcode = TextIO.getln().toUpperCase().toCharArray();
for (int i = 0; i < dcode.length; i++) {
char alpha;
if ((dcode[i] >= 'A' && dcode[i] <= 'Z')) {
int cryp = ((int) dcode[i]) - shift;
if (cryp < (int) 'A') {
cryp += 26;
}
alpha = ((char) cryp);
} else {
alpha = dcode[i];
}
System.out.print(alpha);
}
System.out.print("\n");
}
}
==================================
You need to call these functions now, I have just made it
compile....You need call those functions generate
Output

PLEASE COMMENT if there is any concern.
==========================================
=================================
I'm also having trouble on dividing the code into methods. This is my work done so...
Hello, can someone please fix my code? It runs perfect but I'm having trouble with the index for the incorrect answer array; please run some tests to ensure the code runs properly, thank you! Here is the code: ___________________________________________________________________________________________________________________________ import java.util.Scanner; public class DriverTest{ final static int QuestionTotal = 10; public static void main(String[] args){ // scanner and answer key Scanner scan = new Scanner(System.in); final char[] answers = {'A', 'B', 'C',...
Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...
I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) { int choice; Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result; Scanner scanner = new Scanner(System.in); System.out.print("Enter 1\t UsDollars to Yen:...
Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...
For this code after case 0, I need it to ask the user if they would like to see the menu again and some type of if statement or loop to ask them yes or no and if yes print again and if no end program. So it would ask if they would like to see the menu again then ask what their choice is. If yes print menu and if no end program. import java.util.InputMismatchException; import java.util.*; import java.io.*;...
Please help me with this Java project. I'm trying to create a loop so if user enter value > 12, will prompt them a message and take them back to "How many elements do you wan to enter?". Thanks public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i, j; System.out.print("\n How meny elements do you want to enter? (N should be no more than 12) "); int num...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...
i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...
Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q { public static LinkedList<String> dogs = new LinkedList<String> (); public static LinkedList<String> cats = new LinkedList<String> (); public static LinkedList<String> animals = new LinkedList<String> (); public static void enqueueCats(){ System.out.println("Enter name"); Scanner sc=new Scanner(System.in); String name = sc.next(); cats.addLast(name); animals.addLast(name); } ...