encryption - Java Cipher Program -


firstly, here instructions program put together...

provide main method. should:  input string , shift value  convert upper case  perform following items on alphabetic characters between , z  utilize loop uses postfix incrementing operator o convert character ascii equivalent (type cast) o shift b y shift value entered above  if reach end of alphabe t, wrap around  example: shifted left 2 become y o convert character equivalent (type cast) o output new character  input string , shift value  perform same steps above convert encrypted text plain text  sure input again different encrypted text may entered  main method can call separate method perform encryption/decryption not required. utilize postfix increment/decrement operations , compound assignment operators math. e xample: x++ or x+=2.

the code have far is:

/* jursekgregchapter12t.java greg jursek  program encrypt entered text user input  shift value , decrypt text in same manner. */  import java.lang.*;  import java.util.*;  public class jursekgregchapter12t {     public static void main(string[] args) {     scanner stdin = new scanner(system.in);     string encrypttext; // text encrypted     string decrypttext; // text decrypted     int shiftvalue; // number of spaces shifted via user input       // user enters plain text encryption     system.out.print("please enter text encrypt");     encrypttext = stdin.nextstring();      // user enters shift value     system.out.println("please enter shift value");     shiftvalue = stdin.nextint();      // system prints encrypted text     string encryptedtext = encrypt(encrypttext , shiftvalue); // text has been encrypted     system.out.println(encryptedtext);      // user enters text decryption     system.out.print("please enter text decrypt");     decrypttext = stdin.nextstring();      // user enters shift value     system.out.println("please enter shift value");     shiftvalue = stdin.nextint();      // system prints decrypted text     string decryptedtext = decrypt(decrypttext , shiftvalue); // text has been decrypted     system.out.println(decryptedtext); } // end main           // shift , character manipulation         public static string shift(string enteredtext, int shiftvalue)          {              string convertedtext = "";             for(int = 0; i< enteredtext.length(); i++)             {                 char lowercase = enteredtext.charat(i);                  //convert upper case letters                 char lowercase = character.touppercase(lowercase);                 int charnumber = upperletter;                  //shift letters , wrap text                 int rotateletters = (charnumber + shiftvalue) % 26;                 char shiftletters = (char) rotateshift;                  //populate new string of characters                 convertedtext += shiftletters;             }         return convertedtext;         }          // encryption code         public static string encrypt(string enteredtext, int shiftvalue);         {             string encryptedstring = rotate(enteredtext , shiftvalue);             return encryptedstring;         }          // decryption code         public static string decrypt(string enteredtext, int shiftvalue);         {             int negativeshiftvalue = (-1) * (shiftvalue);             string decryptedstring = rotate(enteredtext , negativeshiftvalue);             return decryptedstring;         }   } //end class jursekgregchapter12t 

at point getting lot of strange errors , i'm not quite sure what's gone wrong...those errors are:

/users/greg/documents/programming/java/jursekgregchapter12t.java:24: error: cannot find symbol         encrypttext = stdin.nextstring();                            ^   symbol:   method nextstring()   location: variable stdin of type scanner /users/greg/documents/programming/java/jursekgregchapter12t.java:36: error: cannot find symbol         decrypttext = stdin.nextstring();                            ^   symbol:   method nextstring()   location: variable stdin of type scanner /users/greg/documents/programming/java/jursekgregchapter12t.java:55: error: cannot find symbol                     char lowercase = enteredtext.charat(i);                                                 ^   symbol:   method charat(int)   location: variable enteredtext of type string /users/greg/documents/programming/java/jursekgregchapter12t.java:58: error: variable lowercase defined in method shift(string,int)                     char lowercase = character.touppercase(lowercase);                          ^ /users/greg/documents/programming/java/jursekgregchapter12t.java:59: error: cannot find symbol                     int charnumber = upperletter;                                      ^   symbol:   variable upperletter   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:63: error: cannot find symbol                     char shiftletters = (char) rotateshift;                                                ^   symbol:   variable rotateshift   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:72: error: missing method body, or declare abstract             public static string encrypt(string enteredtext, int shiftvalue);                                  ^ /users/greg/documents/programming/java/jursekgregchapter12t.java:74: error: cannot find symbol                 string encryptedstring = rotate(enteredtext , shiftvalue);                                                 ^   symbol:   variable enteredtext   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:74: error: cannot find symbol                 string encryptedstring = rotate(enteredtext , shiftvalue);                                                               ^   symbol:   variable shiftvalue   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:75: error: return outside method                 return encryptedstring;                 ^ /users/greg/documents/programming/java/jursekgregchapter12t.java:79: error: missing method body, or declare abstract             public static string decrypt(string enteredtext, int shiftvalue);                                  ^ /users/greg/documents/programming/java/jursekgregchapter12t.java:81: error: cannot find symbol                 int negativeshiftvalue = (-1) * (shiftvalue);                                                  ^   symbol:   variable shiftvalue   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:81: error: illegal start of type                 int negativeshiftvalue = (-1) * (shiftvalue);                                                 ^ /users/greg/documents/programming/java/jursekgregchapter12t.java:82: error: cannot find symbol                 string decryptedstring = rotate(enteredtext , negativeshiftvalue);                                                 ^   symbol:   variable enteredtext   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:83: error: return outside method                 return decryptedstring;                 ^ 15 errors [finished in 0.7s exit code 1] 

any appreciated.

thanks.

after resolving of errors:

/users/greg/documents/programming/java/jursekgregchapter12t.java:56: error: cannot find symbol                 char lowercase = enteredtext.charat(i);                                             ^   symbol:   method charat(int)   location: variable enteredtext of type string /users/greg/documents/programming/java/jursekgregchapter12t.java:59: error: variable      lowercase defined in method shift(string,int)                 char lowercase = character.touppercase(lowercase);                              ^ /users/greg/documents/programming/java/jursekgregchapter12t.java:60: error: cannot find symbol                 int charnumber = upperletter;                                      ^   symbol:   variable upperletter   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:64: error: cannot find symbol                     char shiftletters = (char) rotateshift;                                                ^   symbol:   variable rotateshift   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:75: error: cannot find symbol                 string encryptedstring = rotate(enteredtext , shiftvalue);                                          ^       symbol:   method rotate(string,int)   location: class jursekgregchapter12t /users/greg/documents/programming/java/jursekgregchapter12t.java:83: error: cannot find symbol                 string decryptedstring = rotate(enteredtext , negativeshiftvalue);                                          ^   symbol:   method rotate(string,int)   location: class jursekgregchapter12t 6 errors [finished in 0.7s exit code 1] 

i've spent last 2 hours reading on stuff , still cant understand what's holding code here. i'm novice programmer, java first foray , i'm stuck. have ideas?

those compiler errors, , each 1 tells wrong. here's quick list of issues , resolutions (without writing code you):

  • cannot find symbol: means you're using name that's undefined. instance, on line 24, use stdin.nextstring(), scanner objects not have method called nextstring (you want either next() or nextline()). thus, compiler "cannot find symbol" nextstring because doesn't exist (or charat, because of capitalization error).
  • variable x defined: means sounds like. when error, it's because you're declaring variables twice. once declare variable (e.g. char lowercase), can use (e.g. lowercase = 'a';) within scope without declaring again.
  • missing method body: means you've got method stub declared. unless abstract, methods must have body enclosed in curly braces, , must return type declared return. in particular case, need rid of semicolons @ end of encrypt , decrypt declarations.
  • return outside method means have return statement that's floating in class itself, wouldn't make sense. in case, problem go away once rid of semicolons @ end of encrypt , decrypt, blocks recognized method bodies.
  • illegal start of type more subtle error, in case it's happening because of fact blocks @ class level rather being method bodies. problem go away when fix return outside method issue.

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -