Java密码程序问题

时间:2014-04-06 13:22:50

标签: java

我昨天发布了这个节目,我只是被卡住了。我无法弄清楚为什么我得到了我得到的错误,我已经阅读了一些东西,坦率地说,我一直在努力获得Java。任何帮助表示赞赏...代码和错误要遵循...

/*
JursekGregChapter12t.java
Greg Jursek

This program will encrypt entered text by a user input 
shift value and then decrypt text in the 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 to be encrypted
    String decryptText; // text to be decrypted
    int shiftValue; // the number of spaces that will be shifted via user input


    // User enters plain text for encryption
    System.out.print("Please enter text to encrypt");
    encryptText = stdIn.next();

    // User enters a shift value
    System.out.println("Please enter shift value");
    shiftValue = stdIn.nextInt();

    // System prints the encrypted text
    String encryptedText = encrypt(encryptText , shiftValue); // text that has been encrypted
    System.out.println(encryptedText);

    // User enters text for decryption
    System.out.print("Please enter text to decrypt");
    decryptText = stdIn.next();

    // User enters a shift value
    System.out.println("Please enter shift value");
    shiftValue = stdIn.nextInt();

    // System prints the decrypted text
    String decryptedText = decrypt(decryptText , shiftValue); // text that has been decrypted
    System.out.println(decryptedText);
} // end main


        // Shift and Character Manipulation
        public static String shift(String enteredText, int shiftValue) 
        {

            String convertedText = "";
            for(int i = 0; i< enteredText.length(); i++)
            {
                char lowerCase = enteredText.charAt(i);

                //Convert to upper case letters
                char lowerCase = Character.toUpperCase(lowerCase);
                int charNumber = upperLetter;

                //Shift letters and 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

错误:

/Users/Greg/Documents/Programming/Java/JursekGregChapter12t.java:59: error: variable lowerCase is already 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
5 errors
[Finished in 2.7s with exit code 1]

0 个答案:

没有答案