Results 1 to 7 of 7
  1. #1
    Penguinator is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default Blue pelican Java Project 17b

    My fellow students and I have been struggling to comprehend this lesson given to us over this break. The project's description is as follows:

    You have just been hired by the CIA as a programmer in the encryption department. Your job is
    to write a class called Crypto. One method, encrypt, will accept a String that represents the
    sentence to be encrypted. It will return a String that is the sentence with all v’s (big or small)
    replaced with “ag’,r”, all m’s (big or small) with “ssad”, all g’s (big or small) with “jeb..w”, and
    all b’s (big or small) with “dug>?/”.

    There are two classes: Crypto and Tester. Tester is given as:

    import java.io.*;
    import java.util.*;
    public class Tester
    {
    public static void main(String args[])
    {
    Scanner kbReader = new Scanner(System.in);
    System.out.print(“Enter a sentence that is to be encrypted: ”);
    String sntnc = kbReader.nextLine( );
    System.out.println(“Original sentence = ” + sntnc);
    Crypto myCryptObj = new Crypto( );
    String encryptdSntnc = myCryptObj.encrypt(sntnc);
    System.out.println(“Encrypted sentence = ” + encryptdSntnc);
    String decryptdSntnc = myCryptObj.decrypt(encryptdSntnc);
    System.out.println(“Decrypted sentence = ” + decryptdSntnc);
    }
    }

    While the progress I have made on Crypto is:

    class Crypto
    {
    private String sntnc;
    public String Crypto (String sntnc)
    {
    String x = sntnc;
    return x;
    }
    public String encrypt(String sntnc)
    {
    String finalSntnc = "";

    for(int y = 0; y < sntnc.length( ); y++)
    {
    char nextChar = sntnc.charAt(y);
    switch (nextChar)
    {
    case 'v':
    case 'V':
    {
    finalSntnc = finalSntnc + "ag\',r";
    break;
    }

    case 'm':
    case 'M':
    {
    finalSntnc = finalSntnc +"saad";
    break;
    }
    case 'g':
    case 'G':
    {
    finalSntnc = finalSntnc + "jeb..w";
    break;
    }

    case 'b':
    case 'B':
    {
    finalSntnc = finalSntnc + "dug>?/";
    break;
    }

    default:
    {
    finalSntnc = finalSntnc + nextChar;
    }
    }


    }
    return finalSntnc;
    }

    I am stuck and can't seem to finish the project. Is there anyone that can help me?

  2. #2
    arabin is offline Member
    Join Date
    Apr 2016
    Posts
    1
    Rep Power
    0

    Default Re: Blue pelican Java Project 17b

    [QUOTE=Penguinator;366614]My fellow students and I have been struggling to comprehend this lesson given to us over this break. The project's description is as follows:

    You have just been hired by the CIA as a programmer in the encryption department. Your job is
    to write a class called Crypto. One method, encrypt, will accept a String that represents the
    sentence to be encrypted. It will return a String that is the sentence with all v’s (big or small)
    replaced with “ag’,r”, all m’s (big or small) with “ssad”, all g’s (big or small) with “jeb..w”, and
    all b’s (big or small) with “dug>?/”.

    There are two classes: Crypto and ProjectEncryptionDecryption. ProjectEncryptionDecryption is given below:

    I just renamed the Tester class To ProjectEncryptoinDecryption and just modified it little bit to access Crypto class easi.

    package projectencryptiondecryption;
    import java.util.*;
    /**
    *
    * @author ARANIN
    */
    public class ProjectEncryptionDecryption {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    Scanner kbReader = new Scanner(System.in);
    System.out.print("Enter a sentence that is to be encrypted: ");
    String sntnc = kbReader.nextLine( );
    System.out.println("Original sentence = " + sntnc);
    Crypto myCryptObj = new Crypto(null, "","","");
    String encryptdSntnc = myCryptObj.encrypt(sntnc);
    System.out.println("Encrypted sentence = " + encryptdSntnc);
    myCryptObj = new Crypto(null, "", "", "");
    String decryptSntc = myCryptObj.decrypt(encryptdSntnc);
    System.out.println("Decrypted sentence = " +decryptSntc);
    }

    }


    Here is your Crypto class look like


    package projectencryptiondecryption;
    import java.util.*;
    /**
    *
    * @author ARANIN
    */
    public class Crypto {
    private Scanner reader;
    private String ss;
    private String ans;
    private String neS;
    public Crypto (Scanner re, String ss1, String ans1, String nes1){
    reader =re;
    ss=ss1;
    ans=ans1;
    neS=nes1;
    }
    public String encrypt(String sntnc) {
    reader = new Scanner(sntnc);
    while (reader.hasNextLine()){
    ss = reader.next();
    ss = ss.toLowerCase().replace("v", "ag',r");
    ss = ss.toLowerCase().replace("m", "ssad");
    /* ss = ss.toLowerCase().replace("b", "dug>?/");
    if (ss.contains("dug>?/")) {
    ans = ans + ss+" ";
    continue;
    }*/
    if (ss.contains("ag',r")) {
    ans = ans+ss+" ";
    continue;
    }
    if (ss.contains("big")) {
    for (int i = 0; i < ss.length(); i++) {
    if (Character.toString(ss.charAt(i)).equalsIgnoreCase ("b")) {
    neS = (Character.toString(ss.charAt(i)).toLowerCase().re place("b", "dug>?/"));
    }
    else if (Character.toString(ss.charAt(i)).equalsIgnoreCase ("i")) {
    neS = neS + Character.toString(ss.charAt(i)).toLowerCase();
    }
    else if(Character.toString(ss.charAt(i)).equalsIgnoreCa se("g")){
    neS = neS + (Character.toString(ss.charAt(i)).toLowerCase().re place("g", "jeb..w"));
    }
    else {
    System.out.println("False Loop");
    }
    }
    ans = ans + neS +" ";
    continue;
    }
    ss = ss.toLowerCase().replace("g", "jeb..w");
    ans = ans +ss+" ";
    }
    return ans;
    }

    public String decrypt(String sntnc){
    ans = sntnc.toLowerCase().replace("ag',r", "v");
    ans = ans.toLowerCase().toLowerCase().replace("ssad", "m");
    ans = ans.toLowerCase().replace("jeb..w", "g");
    ans = ans.toLowerCase().replace("dug>?/", "b");
    return ans;
    }

    }

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,469
    Rep Power
    5

    Default Re: Blue pelican Java Project 17b

    Great. You did his assignment for him. The 1337 c0derz that you are... And how do you think this helped? If the OP wants he can hand in your work and claim it's his. Personally I wouldn't because it's a mess.

    Don't spoonfeed the answers. Just don't. There are other ways to become famous. As this is clearly homework, you would be helping more if you asked the OP questions and giving a push in the right directions, explain what errormessages mean, general coding tips etc.

    So far the OP has not asked a question, he just said he was stuck. So the first thing you should do is ask: "Where are you stuck? What is the output? Any error message? What part don't you understand?".

    So the OP: Where are you stuck? What is the output? Any error message? What part don't you understand?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,768
    Rep Power
    22

    Default Re: Blue pelican Java Project 17b

    Hopefully the OP has finished whatever course he was on.
    It's been over 2 years after all.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,469
    Rep Power
    5

    Default Re: Blue pelican Java Project 17b

    Quote Originally Posted by Tolls View Post
    Hopefully the OP has finished whatever course he was on.
    It's been over 2 years after all.
    ... Sometimes I wonder why I still come here... :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,768
    Rep Power
    22

    Default Re: Blue pelican Java Project 17b

    You come here for the atmosphere...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    5,248
    Rep Power
    9

    Default Re: Blue pelican Java Project 17b

    Your message is still valid. And perhaps the OP will now learn before doing the same to a new post.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Getting to know Blue J
    By siblingrivalry in forum New To Java
    Replies: 1
    Last Post: 10-23-2013, 12:36 PM
  2. Replies: 7
    Last Post: 11-27-2012, 11:16 AM
  3. Replies: 6
    Last Post: 11-20-2012, 12:40 AM
  4. Blue Pelican Java: Help with Encryption/Decryption
    By ohwegg1 in forum New To Java
    Replies: 0
    Last Post: 01-29-2012, 01:48 AM
  5. Replies: 30
    Last Post: 08-26-2011, 09:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •