Results 1 to 9 of 9
  1. #1
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Having problems on queue! HELP ME!

    I just want to convert my program to QUEUE
    this whole thing but i cant find any program in the net that would help me do it

    Can anyone help me do this stuff or just post your samples regarding on it

    im creating a Caesar Cipher Code ^_^


    import java,util.*;
    public class SecretCodeDemo {
    public static void main(String[] args) {
    Scanner kbd=new Scanner (System.in);
    int choice = kbd.nextInt();
    String monthString;
    switch (month) {
    case 1:
    encrypt();
    break;
    case 2:
    decrypt();
    break;
    case 3:
    System.out.println("Good bye!!");
    System.exit(0);
    break;

    default:
    System.out.println("Invalid Output.");
    break;
    }

    public class encrypt(){
    try{
    String message;
    System.out.println("Input: ");
    Scanner kbd=nextLine();
    int shiftKey = Integer.parseInt(args[1]);
    shiftKey = shiftKey % 26;

    String cipherText = "";

    for (int i=0; i<plaintext.length(); i++){
    int asciiValue = (int) plaintext.charAt(i);
    if (asciiValue < 65 || asciiValue > 90){
    cipherText += plaintext.charAt(i);
    continue;
    }

    int basicValue = asciiValue - 65;
    int newAsciiValue = 65 + ((basicValue + shiftKey) % 26) ;
    cipherText += (char) newAsciiValue;

    }
    System.out.print(cipherText);
    }
    catch(Exception e){e.printStackTrace();}
    }
    }
    }
    }




    POSSIBLE OUTCOME:

    Message: Data
    Key value ( for each letter ): 2 1 5 4 (for each letter )
    Outcome: Fbze

    Help me out ^_^
    THANKS A LOT!

  2. #2
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Having problems on queue! HELP ME!

    This is my encrypt code
    public class encrypt(){
    try{
    System.out.println("Message: ");
    String ciphertext = kbd.nextLine();
    int shiftKey = Integer.parseInt(args[1]);
    shiftKey = shiftKey % 26;

    String plainText = "";

    for (int i=0; i<ciphertext.length(); i++){
    int asciiValue = (int) ciphertext.charAt(i);
    if (asciiValue < 65 || asciiValue > 90){
    plainText += ciphertext.charAt(i);
    continue;
    }

    int basicValue = asciiValue - 65;

    int newAsciiValue = -1000;

    if (basicValue - shiftKey < 0){

    newAsciiValue = 90 - (shiftKey - basicValue) + 1;
    }
    else{
    newAsciiValue = 65 + (basicValue - shiftKey);
    }
    plainText += (char) newAsciiValue;

    }
    System.out.print(plainText);
    }
    catch(Exception e){e.printStackTrace();}
    }
    }

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Having problems on queue! HELP ME!

    Quote Originally Posted by AnnaPatricia View Post
    I just want to convert my program to QUEUE
    I don't understand your statement above. Can you clarify what it is exactly that you're trying to do, and in particular what a queue has to do with it.

    this whole thing but i cant find any program in the net that would help me do it
    You're likely much better not "finding" any program, but rather writing your own program.

    Can anyone help me do this stuff or just post your samples regarding on it
    I can't speak for others, but until you clarify your problem, there's little help I have to offer. Most of us do best answering direct straight-forward questions.

    im creating a Caesar Cipher Code ^_^
    This most here will understand and know how to do.

    Java Code:
    import java,util.*;
    public class SecretCodeDemo {
        public static void main(String[] args) {
    	Scanner kbd=new Scanner (System.in);
            int choice = kbd.nextInt(); 
            String monthString;
            switch (month) {
    	    case 1:
    		encrypt();
    		break;
    	    case 2:
    		decrypt();
    		break;
    	    case 3:
    		System.out.println("Good bye!!");
    		System.exit(0);
    		break;
                
                default: 
    		System.out.println("Invalid Output.");
                         break;
            }
            
    	public class encrypt(){
    try{ 
    	String message;
    	System.out.println("Input: ");
    	Scanner kbd=nextLine();
        	int shiftKey = Integer.parseInt(args[1]); 
          	shiftKey = shiftKey % 26;  
           
        	String cipherText = ""; 
      
          for (int i=0; i<plaintext.length(); i++){ 
             int asciiValue = (int) plaintext.charAt(i); 
             if (asciiValue < 65 || asciiValue > 90){ 
                cipherText += plaintext.charAt(i); 
                continue; 
             } 
              
             int basicValue = asciiValue - 65; 
             int newAsciiValue = 65 + ((basicValue + shiftKey) % 26)  ; 
             cipherText += (char) newAsciiValue; 
      
           } 
           System.out.print(cipherText);              
          } 
         catch(Exception e){e.printStackTrace();} 
      } 
    }
        }
    }
    I've added [code] [/code] tags to your code above to make it easier to read. You may wish to edit your original post and add these yourself so that others will be able to read and understand your posted code.

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

    Default Re: Having problems on queue! HELP ME!

    Please don't PM people for solutions.
    We won't get to the threads any faster.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Having problems on queue! HELP ME!

    uhm i mean i need to use a circular array queue on the encrypt and decrypt method i need to use.


    Do you think i can use this program?
    How?

    teach me please willing to learn

    public interface QueueADT<T>
    {
    /**
    * Adds one element to the rear of this queue.
    *
    * @param element the element to be added to the rear of this queue
    */
    public void enqueue (T element);
    /**
    * Removes and returns the element at the front of this queue.
    *
    * @return the element at the front of this queue
    */
    public T dequeue();
    /**
    * Returns without removing the element at the front of this queue.
    *
    * @return the first element in this queue
    */
    public T first();
    /**
    * Returns true if this queue contains no elements.
    *
    * @return true if this queue is empty
    */
    public boolean isEmpty();
    /**
    * Returns the number of elements in this queue.
    *
    * @return the integer representation of the size of this queue
    */
    public int size();
    /**
    * Returns a string representation of this queue.
    *
    * @return the string representation of this queue
    */
    public String toString();
    }

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Having problems on queue! HELP ME!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Having problems on queue! HELP ME!

    thanks for your help


    Moderator? What a good member..


    Thanks anyway

  8. #8
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Having problems on queue! HELP ME!

    Please close this thread...


    Thanks you !!

  9. #9
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Having problems on queue! HELP ME!

    Quote Originally Posted by AnnaPatricia View Post
    thanks for your help


    Moderator? What a good member..


    Thanks anyway
    You need to understand that people on here are willing to give you help for free! However, it is up to the OP to post a coherent question and make it as easy as possible for the volunteers on here to provide their assistance.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Replies: 0
    Last Post: 05-27-2011, 08:46 AM
  2. Priority Queue
    By Suende in forum New To Java
    Replies: 19
    Last Post: 04-25-2011, 08:46 AM
  3. Queue
    By DCY in forum New To Java
    Replies: 6
    Last Post: 05-04-2010, 08:07 PM
  4. Queue in the GUI
    By jonywalker123 in forum Advanced Java
    Replies: 2
    Last Post: 03-06-2009, 08:33 PM
  5. Using a queue
    By Krmeus in forum New To Java
    Replies: 0
    Last Post: 12-10-2007, 03:38 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
  •