Results 1 to 9 of 9
- 08-16-2012, 11:38 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 13
- Rep Power
- 0
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!
- 08-16-2012, 11:42 AM #2
Member
- Join Date
- Aug 2012
- Posts
- 13
- Rep Power
- 0
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();}
}
}
-
Re: Having problems on queue! HELP ME!
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.
You're likely much better not "finding" any program, but rather writing your own program.this whole thing but i cant find any program in the net that would help me do 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.Can anyone help me do this stuff or just post your samples regarding on it
This most here will understand and know how to do.im creating a Caesar Cipher Code ^_^
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.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();} } } } }
- 08-16-2012, 12:40 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 08-16-2012, 01:33 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 13
- Rep Power
- 0
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();
}
- 08-16-2012, 04:01 PM #6
Re: Having problems on queue! HELP ME!
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 04:20 PM #7
Member
- Join Date
- Aug 2012
- Posts
- 13
- Rep Power
- 0
Re: Having problems on queue! HELP ME!
thanks for your help
Moderator? What a good member..
Thanks anyway
- 08-16-2012, 04:35 PM #8
Member
- Join Date
- Aug 2012
- Posts
- 13
- Rep Power
- 0
Re: Having problems on queue! HELP ME!
Please close this thread...
Thanks you !!
- 08-16-2012, 05:18 PM #9
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Having problems on queue! HELP ME!
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
Similar Threads
-
Servlet, Glassfish JMS java.lang.IllegalArgumentException: MQ:Queue:Invalid Queue Nam
By akasozi in forum Java ServletReplies: 0Last Post: 05-27-2011, 08:46 AM -
Priority Queue
By Suende in forum New To JavaReplies: 19Last Post: 04-25-2011, 08:46 AM -
Queue
By DCY in forum New To JavaReplies: 6Last Post: 05-04-2010, 08:07 PM -
Queue in the GUI
By jonywalker123 in forum Advanced JavaReplies: 2Last Post: 03-06-2009, 08:33 PM -
Using a queue
By Krmeus in forum New To JavaReplies: 0Last Post: 12-10-2007, 03:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks