Is this a good or bad implementation?

My teacher had us implement a class that does the following:
1) Takes a string and shifts all characters forwards or backwards through an array.
2) Reverses all characters.
3) Reverses all words
4) Returns the encrypted string.
The way I decided to implement it is by create a class StringProcessor that does all of that.
I made all the methods in it private and had a constructor that takes an integer and a string as arguments. The constructor then runs each of the private methods in order to process the string. It has one public query that just returns the finished string. I also stuck a private inner class CharacterArray that basically matches each character in the string with a character in the array and then shifts it the appropriate amount. (by shift I mean a shift of one would mean "a" goes to "b").
The other two classes I made are called StringEncrypter and StringDecrypter. They don't have a constructer, but simply pass the string (with the appropriate changes made to it) to the StringProcessor's constructor.
What I'm not so sure about is if I was right in making those methods private and letting the constructor handle it. My thinking was that it would keep outside classes from knowing what that method is doing and it would leave the processing of that string entirely up to the constructor, which would eliminate a client from messing something up in the processing.
Any advice is appreciated. I will include code if anyone wants to see what I'm babbling about.
Thanks

package stringEncryption;
import myContainers.Queues.*;
import myContainers.Stacks.*;
* This class models a StringProcessor.
* A StringProcessor's job is to
* take a string (supplied by client
* as argument) and split it into
* words. Each of the word's letters are then
* shifted from -5 < 0 < 5 in a character
* array. As each letter is shifted, it is
* added to a stack. Once the word has
* been processed completely, the letters are
* "popped" back out into a string. The result
* is a word whose's letters are shifted
* and whose letters are in reverse order.
* For example,
*   The word "At" with a shift of -1 would give
* the letters "zs" after being shifted.
* Once shifted, the letters would be added to a stack
* and the new finished result would be "sz".
*   This is repeated for every word in the string.
* After all words have been processed, they are put
* into a Stack where they come out in reverse order.
* I chose to make almost all methods private for two
* reasons.
* 1) The methods need to be performed in order, which
* I think is done easily by calling the methods
* in the constructor. That way a user can't make a mistake
* when encrypting/decrypting.
* 2) Seeing as the point of the assignment is to encrypt and
* decrypt a string I feel that the methods should be somewhat
* guarded from outside programs.
public class StringProcessor{
   * Creates a new StringProcessor, shifts
   * and reverses all A to Z and a to z characters,
   * and reverses all words of the sentence.
   * Require:
   *     -5 < shift < 5
   *     string != null
  public StringProcessor(int shift, String string){
    this.stringStack = new StackImplementation<String>();
    this.stringStack.setStackType(1);
    charShift = new CharacterShifter(shift);
    breakString(string);
    while(!this.queue.isEmpty()){
      shiftChars(this.queue.front());
      this.queue.remove();
    assembleString();
   * Return the finished string.
  public String finishedString(){
    return this.completedString;
   * Split the string into tokens
   * and insert each word into a Queue.
   * Require:
   *     string != null
   * Ensure:
   *     !queue.isEmpty()
  private void breakString(String string){
    this.queue = new QueueImplementation<String>();
    this.queue.setQueueType(1);// Creates a LinkedQueue
    int i = 0;
    int j = 0;
    while(j < string.length()){
      if((string.charAt(j) == ' ') ||
         (string.charAt(j) == ',') ||
         (string.charAt(j) == ';') ||
         (string.charAt(j) == '.')){
        this.queue.append(string.substring(i, j) + string.charAt(j));
        j = j + 1;
        i = j;
      else
        j = j + 1;
   * This method takes a string
   * and shifts each character of the
   * string. After each character is
   * shifted, the characters is
   * placed into a DynamicStack
   * and "popped" back out.
   * The result is a word whose
   * letters have been shifted and
   * whose letters are now in reverse
   * order.
   * Require:
   *     string != null
   * Ensure:
   *     if(string.startsWith("x") && string.endsWith("y")
   *        charShift.shift(string.startsWith("y") && string.endsWith("x"))
  private void shiftChars(String string){
    Stack<Character> charStack = new StackImplementation<Character>();
    charStack.setStackType(1);
    char[] charArray = string.toCharArray();
    int i = 0;
    while(i < charArray.length - 1){//length - 1 was chosen because
                                    //the last character is always
                                    //a " " or "," or ";" or "."
                                    // and should never be shifted.
      charStack.push(charShift.shift(charArray));
i = i + 1;
String s = "";
while(!charStack.isEmpty()){
s = s + charStack.top();
charStack.pop();
s = s + charArray[charArray.length - 1];//adds the last (unshifted)
//character to the end of
//the string.
this.stringStack.push(s);
* This method assembles the
* string stored in a stack.
* Ensure:
* !completedString.isEmpty()
private void assembleString(){
this.completedString = "";
while(!this.stringStack.isEmpty()){
completedString = completedString + this.stringStack.top();
this.stringStack.pop();
private CharacterShifter charShift;
private Queue<String> queue;
private Stack<String> stringStack;
private String completedString;
* This class takes a character (supplied
* by a client) and shifts it the appropriate
* number of spaces through the alphabet.
* The number of spaces each character is shifted
* by is supplied by the client upon creation of
* this class.
* For example, "A" with a shift of 3
* would become "D". and "a" with a shift of -3
* would become "X".
private class CharacterShifter{
* The client supplies the amount it would like
* each character to be shifted by as an argument.
* A new character array is created using the letters
* A to Z and a to z.
* Require:
* amount != null
* Ensure:
* charArray[52] = "a" to "z" && "A" to "Z"
public CharacterShifter(int amount){
this.charArray =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
this.shiftAmount = amount;
* Shift this character by the specified amount.
* Require:
* char c != null
* Ensure:
* if(c == charArray[i])
* c = charArray[i + shiftAmount]
public char shift(char c){
int i = 0;
while (i < charArray.length){
if (charArray[i] == c){
if(i + shiftAmount > 51)
i = i - 52;
if(i + shiftAmount < 0)
i = i + 52;
c = charArray[i + shiftAmount];
i = charArray.length;
else
i = i + 1;
return c;
private char[] charArray;
private int shiftAmount;

Similar Messages

  • Uh...I'm not sure if this is good or bad.

    Alrighty, I recently downloaded cocktail, and did an Apple Hardware Test because I was having force reboot issues and I wanted to make sure it wasn't a hardware problem. Now, it's been about 2 days, and I haven't had to force reboot because of an application freezing, but I just noticed something new. Before I installed cocktail, it used to take my computer about 10 minutes to start up after I pressed the power button (the less peripherals I had, the less time it took). It would spend a few minutes on a screen with a flashing globe, then a few minutes on a screen with the finder face flashing interchangeably with a question mark, then it would go to the gray screen with the apple on it, then to the login window. I turned on my computer this morning, with my USB printer cable and ethernet cable plugged in, and it went straight to the gray screen with the apple, then to the login window. Is this a good thing or bad thing?

    As far as the flashing question mark and globe icons are concerned, your computer had lost track of its startup volume and was searching through the possibilities. The globe icon indicates that it is looking for a network to start from and the question mark indicates that it is looking for an OS X volume. To fix this, if you haven't already, go to System Preferences > Startup Disk and reselect your internal HD as the startup volume.
    From what you have described, this issue does seem to have corrected itself, and the faster start up is what one would normally expect. I think that you have absolutely no reason to reinstall your system.

  • Looking at using apple TV to assist with photo editing on my MB Pro, is this a good idea?

    I have a mac book pro 13 (2011) I am looking at using the Apple TV to display my MBP to my TV for photo editing, anyone able to let me know if they either have done this before, good or bad, or if you think it would work if you have not tried it yourself. Will also be using it for TV etc not just editing.
    Thank you in advance.
    Currently have Lightroom 5 and PS CC for editing etc.

    So you plan to mirror the MBP's display via the Apple TV to your TV and edit off that image?
    Right off the bat I can see problems with color calibration between the MBP's display and the TV.  I edit in Aperture and while the images when displayed on my TV vi Apple TV look ok they are not exactly the same as they appear on the iMac.
    So I guess it depends on what you plan to do with the images once you have edited them. Is there any printing involved? That brings in another whole layer of complexity.
    For sharing on the web and with family and friends it should be Ok, for anything more professional you'll need to get everything calibrated.
    regards

  • Is this good or bad in terms of battery life?

    So I have a question, my usage is 1 hour, 11 minutes; standby is 13 hours, 29 minutes. This is since the last full charge on my iphone4s and now the battery is at 68%. Is this good or bad, and the thing is when I used certain apps like words with friends even for 2-3mins I actually noticed the battery life going down 2%, and I know that because I have the option for showing the battery percentage switched to on. It's frustating that I'm doing the simplest task like going through settings and the battery is draining so quickly. Does anyone have and suggestions about increasing the battery life?

    The short battery life is an issue of iOS5 that should be fixed with the next updates. ( also hope that Apple would fix it fast)

  • BAPI Check in BADI Implementation

    Dear All,
    We have made an enhancement through BADI in ME21N / ME22N transaction like validating certain entries, in that I am checking the t-codes ME21, ME21N, ME22 and ME22N. If it fails then PO wonu2019t create and populate some messages.
    Now there is one custom program which creating POu2019s through calling BAPI in the program and itu2019s not validating the above as its calling through custom program.
    (i.e  SY-TCODE eq SE38)
    Now how I should put a condition on BAPI in my BADI implementation?? If it is normal user exit, we can use runtime structure T158 and check the TCODE in that. But as I am using the BADI ME_PROCESS_PO_CUST with the method CHECK doesnu2019t have any transaction code info.
    And currently I have an idea of using the GET / SET Parameters and need to set in the custom program and get that info in BADI? But I donu2019t know whether this idea good or not?? If anyone has any idea please let me know?
    Thanks,
    Raghu.

    Hi Raghu,
    If sy-tcode ne 'ME21'
    and sy-tcode ne 'ME21N'...
    IMPORT lv_data ....
    do processing...
    endif.
    Best regards,
    Prashant

  • Sending Email using cl_bcs from a badi implementation

    Hi,
    I have written my code to send Email, inside AFTER_SAVE method of BADI Implementation of DOCUMENT_MAIN01.
    Now this method of cl_bcs requires COMMIT WORK for the mail to be sent. And inside BADI implementation, we cannot write a COMMIT statement.
    What is a workaround for this? While going through few other posts, I came across remote enabled FMs.
    Is that the only way? Can I use some additions like STARTING NEW TASK etc. Following is the call used in case of cl_bcs:
       CALL METHOD G_REF_SEND_REQUEST->SEND(
              EXPORTING
                I_WITH_ERROR_SCREEN = 'X'
             RECEIVING
                RESULT              = G_SENT_TO_ALL ).
    I also tried using SO_NEW_DOCUMENT_SEND_API1 STARTING NEW TASK and it works fine. But the subject length is a constraint their.
    Please suggest.
    Thanks in advance.

    Hi friend.
    *& Report  ZTEST_273068_EMAIL_CL_BCS
    REPORT  ZTEST_273068_EMAIL_CL_BCS.
    CONSTANTS:
        gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS',
        gc_raw     TYPE char03 VALUE 'RAW'.
      DATA:
        gv_mlrec         TYPE so_obj_nam,
        gv_sent_to_all   TYPE os_boolean,
        gv_email         TYPE adr6-smtp_addr,
        gv_subject       TYPE so_obj_des,
        gv_text          TYPE bcsy_text,
        gr_send_request  TYPE REF TO cl_bcs,
        gr_bcs_exception TYPE REF TO cx_bcs,
        gr_recipient     TYPE REF TO if_recipient_bcs,
        gr_sender        TYPE REF TO cl_sapuser_bcs,
        gr_document      TYPE REF TO cl_document_bcs.
      TRY.
          "Create send request
          gr_send_request = cl_bcs=>create_persistent( ).
          "Email FROM...
          gr_sender = cl_sapuser_bcs=>create( sy-uname ).
          "Add sender to send request
          CALL METHOD gr_send_request->set_sender
            EXPORTING
              i_sender = gr_sender.
          "Email TO...
          gv_email = '[email protected]'.
          gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
          "Add recipient to send request
          CALL METHOD gr_send_request->add_recipient
            EXPORTING
              i_recipient = gr_recipient
              i_express   = 'X'.
          "Email BODY
          APPEND 'Hello world! My first ABAP email!' TO gv_text.
          gr_document = cl_document_bcs=>create_document(
                          i_type    = gc_raw
                          i_text    = gv_text
                          i_length  = '12'
                          i_subject = gc_subject ).
          "Add document to send request
          CALL METHOD gr_send_request->set_document( gr_document ).
          "Send email
          CALL METHOD gr_send_request->send(
            EXPORTING
              i_with_error_screen = 'X'
            RECEIVING
              result              = gv_sent_to_all ).
          IF gv_sent_to_all = 'X'.
            WRITE 'Email sent!'.
          ENDIF.
          "Commit to send email
          COMMIT WORK.
          "Exception handling
        CATCH cx_bcs INTO gr_bcs_exception.
          WRITE:
            'Error!',
            'Error type:',
            gr_bcs_exception->error_type.
      ENDTRY.
    Just Execute it.
    Regards,
    Thrimu

  • BADI implementation is not working in background for MRRL

    Hai frnds,
    BADI: MRM_WT_SPLIT_UPDATE is used for deducting withholding tax in MRRL(Invoice verification). This BADI was implemented and working fine in foreground, but not working in background.
    After implementing the BADI, the standard method of calculating TDS(from vendor master) is over written by BADI implementation.Now standard deduction is also not workijng in background.Plz help me to solve it.
    Bala.V

    HI,
    COR6N is the Enjoy Transaction and sap does not suggest to write the BDC on these transaction as most of these transaction uses the GUI elements foe better display and which cannot be recorded while processing the BDC in back ground.
    Check for the Normal transaction and write the BDC for it.
    Or
    Pass X to Rcommit flag in the CTU_PARAMS option and check.

  • Placing a PDF file in an InDesign Doc and PDF again for a vendor- Good or Bad?

    Current debate in the graphics department is
    Is it good or bad to place a PDF (general Press Quality) into an InDesign document and then creating a new PDF file with print vendor settings from that document?
    My thought is that you in some cases are double compressing, lower dpi images getting compressed, RGB color mode images okay on layout but now are converted to CMYK and shift in the PDF.
    Are there other issues and if so what are they.
    Also is there an easy way to check ppi, color mode and compression of an acrobat PDF? I mean other than doing a preflight and searching into each image folder twenty levels deep. FlightCheck and Enfocus are not options,
    too many vendors and not enough time.
    Thank you all in advance for your words of wisdom.

    Dov, I just got off the phone with a trusted professional in the Prepress field at a quite reputable print house, and he said "Dov is the guru of PDFs, ask him this...Will the InDesign CS3 preflight see the characteristics of a PDF (color mode, dpi(ppi), compression) if the original placed PDF is created as a pdf .X4 (1.7)? Ask him also if you were to use one form of compression (say lossless) in the original PDF, and then another form(say lossy) in the vendor PDF would it hold both or convert the first PDF compression to the second form?"
    Any other responses are also welcomed.

  • Goods and Bads with the 6110 Navigator

    Hi
    New user of this forum and a proud owner of a Nokia 6110 Navigator. I had the 6280 but after 2 SW upgrades and still problem with it, I gave up.
    First impression of the 6110 is good, but I found a couple of small things that ”irritates” me.
    1 – The timer function when you write “0200” and press options instead of green (call) button.
    2 – The original headset is too cheap to be an expensive phone like this, should be more like Koss “plug-in-your-ear” kind of headphones, instead of the small “put-close-to-your-ear” thing that is included.
    Also, the straight up cable from the top of the phone is no good. Makes the phone lie bad in the pocket. I also guessing that this cable is going to snap after a while. Why not a 90 degree “adapter” or something?
    3 – When you sending an SMS, on my 6280 you could choose “last used number” or something like that, now you have to choose name, and then number, and then OK to go back to the SMS.
    Well.. that’s it so far. Anyone else have goods and bads about this phone ?
    mvh / regards
    Timmy

    hi im havin same issues!!
    i went from 6280 to 6110 after i smashed it
    1.first off i didnt kno of the timer option...good bcoz it was annoyin not havin a stopwatch
    2. that "recent use list"...lack of it...is annoying. i just made groups of ppl i msg most
    3. menu organisation is confusing
    4. in call history, it only shows most recent time for that entry, ven if they rang 5 times that day, also they dont show call long eg duration of 3mins 40secs
    5. on my 6280, i had a shortcut menu as mi left select button, cant do this now
    6. power button is end call button, lotsa accidental turn offs
    7. cant turn off start up tone
    oh well i still like it

  • Bridge CS3 on opening: "This Application may perform badly"

    I recently restored my PC to factory condition to troubleshoot performance problems in CS3 Production Premium. I reinstalled all my programs, but it got a little messy when I restored my backup files from an external hard drive. Lots of files ended up in different locations and some were duplicated.
    I wanted to use Bridge to try to reorganize everything, but I get this message when opening Bridge:
    "This application requires an Intel 4 Pentium Celeron, Intel Core Duo or Intel Core 2 Compatible processor (C01/6/5895)"
    and
    "This application may perform badly. Are you sure you want to continue?"
    I am running Vista Ultimate 64-bit on a 2-month old HP Pavilion d5000t desktop with an Intel Core(TM)2 Quad CPU @ 2.66GHz and 8GB RAM which should exceed the minimum requirement.
    What should I do? Performance on my PC is still not good. Premiere opens without a message, but is sluggish; Encore freezes; forget about After Effects.

    And or course the fact that the restore of the backup was "a little messy"
    may not bode well--it's possible some files were restored that should not
    have been and that parts of the OS or Apps are hosed.
    My advice would be to deactivate/uninstall the Adobe apps, restore the
    system again to factory condition, install any operating system updates, and
    then reinstall your Adobe apps. Now check them out: are they running at the
    expected speed? If so--and they probably will be--then carefully and
    selectively restore exactly the data you need to restore and to the proper
    locations. Be careful that your backup files are just data and not program
    files or parts of program files.
    Trez

  • BADI implementation for NOTIF_EVENT_POST not getting triggered

    Hi All,
            We have created an implementaion for the NOTIF_EVENT_POST. And it was working fine previously. Now it is not working for some reason. In fact issue is that the implemetation is not getting triggerd at all. I have put a BREAK-POINT statement in the code, but does not even goes into the code.
    I have checked all the properties. It is active. The table V_EXT_IMP has a entry corresponding to the BADI definition and implementation.
    I tried to debug the standard transaction IW52 (which uses this). The program runs till the FM call for CL_EXITHANDLER=>GET_INSTANCE. It created a instance also. But it does not get inside the call for the method of the BADI LR_BADI_INST->CHECK_DATA_AT_POST.
    I am at a fix now. Can somebody answer this issue? It would be very helpful.
    Regards
    Barada.
    Edited by: Baradakanta Swain on Aug 5, 2008 4:06 PM

    I did not get the issue with the BADI implementation. But as our time line was very tight, we moved the code to BTE event for Updating Notifications.
    This required a little tweaking of the code and now it is working.
    I am marking it ANSWERED so as to remove it from the list of unanswered questions.
    Regards
    Barada

  • Accessing internal table declared outside of BAdI  implementation

    I am working on a BAdI implementation and within the BAdI, I need to manipulate the data of an internal table that is declared in the calling routine.  This internal table is not a parameter to the BAdI call.  I am wondering is there a way to access the internal table that is not recognized by the BAdI implementation?  If so, what's the syntax to do this?
    I know in debug mode, I am able to access the content of the internal table by using (Program)Itab.  But I get a syntax error when accessing the internal table using (Program)Itab syntax. 
    Any help is appreciated!

    Thanks, Max.
    I tried your method, but I am getting a short dump due to type conflict.  I think it's because the internal table I'd like to access is declared using the following syntax:
    data: begin of itab occurs 0,
          end of itab.
    Therefore, when processing the assign statement, the field-symbol is being treated as a structure...
    I tried to change the field-symbol type to any, but after that, I can't modify the table content using loop at type of syntax..
    Do you have any other suggestions? 
    Thanks very much!

  • Migrated BADI Implementation not triggering in ECC 6.0

    Hi Experts,
    Need your urgent assistance how to deal with migrated BADI implementation which is not triggering in ECC 6.0. This is for PO (ME_PROCESS_PO_CUST). In the original version (4.6) it was working fine. But when this is migrated to ECC 6.0, it's not firing. Please help to trigger this one in ECC 6.0.
    Points will be awarded and thanks in advance,
    LM

    Hi LM,
    Can you just paste the code in the BADI.(The method in which code is there)
    Is this BADI implemented and in the Active status.
    Check in SE19 if the implementation exist or not?
    There may be chances that some condition is not met which can trigger this BADI. Have you read the documentation of the BADI?
    Regards,
    Atish

  • BADI  implementation in ECC 6.0

    I want to put a validation when changing business partner details using tcode BP but it seems there no user exists but BADIs but the BADIs that i am getting i think can only be used after the update has taken place. i have BADI ADDRESS_UPDATE and i need to know ho i can implement it in ECC 6.0. I tried SE18 but its saying "Create" operation is possible only for enhancement spots. how best can implement it

    Hi Willard,
    Identify ur enhancement spot. Go to SE18, give the enhancement spot name and display.
    You can see your BADI in that spot. Click on the button 'Implement Enhancement Spot (F6)'.
    Give a name for your enhancement implementation, select ur badi to be implemented in that spot. Give proper name to ur badi implementation.You can now put ur code in that implementation.
    Check this blog of Thomas Weiss.
    /people/thomas.weiss/blog/2006/04/18/how-to-implement-a-badi-and-how-to-use-a-filter--part-4-of-the-series-on-the-new-enhancement-framework
    It clearly explains how you can implement BADI of an enhancement spot in ECC 6.0
    Regards,
    Soumya.
    Edited by: Soumya Jose on Feb 5, 2009 2:14 PM

  • What is a good download broadband speed. Mine is 4.17mb/s. Is that good or bad?

    What is a good download speed. Mine is 4.17mb/s is this good or bad?

    It's average. Do you have cable or DSL? I'm moving into an apartment that has cable speeds of up to 20 megabits per second. Cable speeds do vary and, at the low end, run around 5 megabits per second.
    So - cable or DSL. If cable, call your local ISP and see if they have a package with higher Internet speeds.
    Clinton

Maybe you are looking for