My decoding/encoding program that almost works.  What's wrong?

I've been working on the following program. After it prompts the user to enter a "code," it is then supposed to examine it and either encode or decode it, depending on what the user entered. All entries from the user that are meant to be decoded need to be inputted in this form: "lkdhe lakdh idhal" (1 space after every five letters, and it can only consist of lower or uppercase letters and the numbers 1-5).
If anything else is entered by the user, the program will encode it. However, I can only get the program to call the encode function, the decode function only comes up when I enter in 1 letter to the console. I'm pretty sure the problem is concerning this loop which is suppose to test to see if the user entered in anything other than a letter or number. I don't think it's doing what I want it to do though. I have another loop to test for the required spaces, and I know that one is working.
for(n = 0; n <= s.length() ;n++)
          s1 = s.substring(n);
          if(Code.CODE1.indexOf(s1) == -1)
               return false;
     }Here is the rest of the code:
import java.util.Scanner;
public class Enc1
public static void main (String []args)
     //String message = args[0];
     //String codedMessage = args[1];
     boolean valid = false;
     int i;
     int j;
     Scanner keyboard = new Scanner(System.in);
    System.out.println("Enter a code");
    String code = keyboard.nextLine();
     System.out.println(code);
     if (isCoded(code))
          System.out.println(decode(code));
     else
          System.out.println(encode(code));
public class Code{
     private static final String CODE1 = "HTNZUL5m3lDQchenpIuORws1jPgVtzKWbfBxXSArdayCJkvqGiF2YoM4E";
     public static final String CODE2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,.;:";
    public static String encode (String message)
          message = "Encode called";
          return message;
         //CODE1.charAt(0);  //0 will equal H
         //CODE1.indexOf(CODE1, 0); //Not sure what it returns
    public static String decode (String codedMessage)
          codedMessage = "Decode called";
          return codedMessage;
     public static boolean isCoded(String s){
     int n;
     int m;
     boolean valid = true;
     String s1;
     for(n = 0; n <= s.length() ;n++)
          s1 = s.substring(n);
          if(Code.CODE1.indexOf(s1) == -1)
               return false;
     for(m = 5; m <= s.length()-1; m = m+6)
               if(s.charAt(m) == ' ')
                     valid = true;
               else
               return false;
     return valid;
    }Any suggestions? I hope I explained my problem clearly enough, I'm a little burnt out on this program, I've been working on it for hours. Any help would be greatly appreciated.

Hey Bud,
I think it wouldnt be really clean to mention
boolean valid = true;in the beginning of your for and if.
I would personally start of by making my booleans false in the beginning and changing it on logic.
HTH

Similar Messages

  • Need a free download for a Video Capture program that will work on my Mac Powerbook G4.

    I need a free download for a video capture program that will work on my Powerbook G4 OSX 10.5.8 lap top, not sure but I think has 32 bits. Have already  tried Debut and it just wasn't what I wanted. Anyone know of any that would work?

    Do you not have iMovie?

  • Since I upgraded to os 10.4.8 microsoft office is no longer supported. Is there a program/programs that will work?

    Since I upgraded to os 10.4.8 microsoft office is no longer supported. Is there a program/programs that will work?

    what version Office is it that youre using?
    current Office for Mac 11"  works perfect for everyone.
    If you need a free version, try Open Office.
    Check with MS for compatability issues and resolution.

  • What do your recommend in Mac programs that will do what MS Publisher will

    What do your recommend in Mac programs that will do what MS Publisher does, but better for less?
    I am not sure where I should post general software questions so if this is not the correct one please let me know where I should post a question like this in the future.
    Thanks
    Martin Brossman

    http://store.apple.com/us/product/MB624Z/A?mco=MTIxODk3Mw
    Read the section on "Pages".

  • Why won't my pandora work when I'm not on wifi? I have the cellular data on for it but I never works. Also pandora isn't the only app of mine that does that.. What's wrong with it??

    Why won't my pandora work when I'm not on wifi? I have the cellular data on for it but I never works. Also pandora isn't the only app of mine that does that.. What's wrong with it??

    You're welcome.
    Voicemail is left at your carrier's server. That will continue to work unless you report your iPhone as lost or stolen with your carrier.
    You may never find it again and you can't if the iPhone remains offline or out of service which means the iPhone is powered off or doesn't have cellular reception.

  • My iphoto doesn't work, it just keeps loading and never works. what is wrong and how do i get it to load?

    my iphoto doesn't work, it just keeps loading and never works. what is wrong and how do i get it to load?

    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • After i use 4.3.3 for iphone 4. the notification for facebook and yahoo do not work. what is wrong? anyone can help?

    after i use 4.3.3 for iphone 4. the notification for facebook and yahoo do not work. what is wrong? anyone can help?

    I am also on my forth hard drive on the same model.
    When I unpacked the computer, the hard drive did not include OS X either. Actually, it was completely blank. Did not even have a partition table! I have also had random problems with the machine not charging.
    I have replaced the drive myself with an SSD after figuring the Apple Certified technicians were incompetent. Now even the SSD is starting to fail
    I have bought an HP laptop and setup Ubuntu on it. Hope it turns out better than my previous four various Mac models. All have had various repeating hardware issues that Apple Certified technicians have been unable or unwilling to correct.

  • I want to play candy crush on Facebook and it says i need latest version of adobe flash player, i downloaded it and it still doesn't work. i uninstalled and re installed and still not working. what is wrong? what do i need to do,

    i want to play candy crush on Facebook and it says i need latest version of adobe flash player, i downloaded it and it still doesn't work. i uninstalled and re installed and still not working. what is wrong? what do i need to do,

  • The left half of my screen isn't working, what is wrong?

    The left half of my screen is not working, what's wrong?

    Have you performed a reset? Tap and hold the Home button and the On/Off button for approximately 10-15 seconds, until the Apple logo appears. Release both buttons and await restart.

  • Every Day A Program That Once Worked, Stops Working Properly...

    Sorry, but don't know whether to post in 10.4.6 forum or the Intel Mac Forum, so I'm doing both.
    I don't know what I've installed on my Mac that's making programs act buggy, but programs that worked flawlessly in recent memory are now quitting unexpectedly with the simple selection of a button in a dialogue window or selecting a Menu Item.
    These programs (SO FAR) are Microsoft Office 2004, Azureus 2.4.0.2 (Universal) and Graphic Converter 5.8.2.
    The only thing I can recall adding to my system recently (because of Office failure) is OpenOffice and X11. Other than that I'm at a loss as to why programs are one after the other, suddenly presenting problems.
    Any insight from anyone...PLEASE!!! TIA.
    (I'm Intel Core Duo, 1 Gig RAM, 10.4.6)

    It tells us this is good news. It tells us the issues are limited to your user account.
    Log back into your normal user account:
    Here's the whole litany for thoroughly checking your home folder.It doesn't take so long as it looks.
    1. Navigate to ~(yourhome/library/fonts - drag this folder to the desktop.
    • Restart and test your applications.
    • If they work start adding the fonts back few at a time.
    (Likely suspects are Times RO & Helvetica Fractions)
    2. Check Preferences Thoroughly;
    • Navigate to ~(yourhome/library/preferences drag this folder to the desktop.
    • Restart and test your applications.
    • If this works, save the old preferences folder somewhere else or on disk, name it "old prefs" .
    ** Note: A very important file is the "com.apple.Mail.plist" preference file located in the Preferences folder which contains all email account settings and general mail preferences (hold this one and replace if your problem is not with Mail).
    You'll have to go through some of your System Preferences and apps to set the preferences back to how you like them. (Or if you have the time and inclination, "cherry pick" through until you find the problem one or two.)
    3. Check Permissions Inside Home Folder
    • Navigate to yourhome/library.
    • Get Info (Command - i) on folders for apps you are having problems with.
    • Open the "Ownership & permissions" disclosure triangle.
    • Make sure you are the owner, with "read and write" access.
    • Click on "apply to all"
    • If this is correct, open the "Applications Support" folder and do the same procedure (Command+I) for the folders with the names of the applications you are having trouble with.
    Note:
    The reason to check this is because repairing permissions with Disk Utility doesn't touch permissions inside your home folder.
    4. Navigate to yourhome/library/caches and drag this folder to the trash, then log out and back or restart. There is no need to replace this folder.
    -mj
    [email protected]

  • Hi. I need a apple program that can work and open Office 7 Publisher

    Hi. I am new to apple computing and I find that my work in office publisher is not able to open on this Mac I have Pages but that is the only program I have on here.
    Can any help me with a suggestion whit what program Apple has that is comparable with this window format?

    I have a copy of Libre Office here, and I have a sample .pub file downloaded from MS. I can not open it using Libre Office, please point me to the method you used.
    But ....
    I just found (in the impress module) a listing for Publisher, unfortunately it fails when opening the sample file (looks like a text only import), I will look for another file to test with.
    Thanks for the lead.
    Update:
    It does work:
    Downloaded Publisher Template, opened and re-saved in Libre Office Draw.
    To the OP, download Libre Office, Viking should get the solved award.

  • Office programs that'll work with 10.2?

    I'm looking for some type of office program to use with my eMac with 10.2 currently installed, tired open office, but not supported i guess, maybe an older version but its not off the site anymore.
    Know of any that might work?

    You can get the freeware AbiWord, a word processor, which is equivalent to M$ Word http://www.abiword.com/
    NeoOffice (freeware) is equivalent to Microsoft Office. It can open Excel files, Word files & PowerPoint files. You can also create these types of files that can be opened by PC users. However, it requires OS 10.3. Download the OS 10.3 version of Neo Office here.
    http://www.neooffice.org/neojava/en/olddownload.php#download
    Neo Office v3.0 requires OS 10.4.x.
    Buy a used copy of M$ Office 2004. It will operate on OS 10.2.x
     Cheers, Tom

  • My 2nd mini iPad in a year and same problem happened,it stopped working. what's wrong with mini iPads?!

    I got a replacement to my daughter’s iPad mini in September b/c her 1st one stopped working and now it happened again. I took it to the Apple store and  i was told that there's  nothing they can do. What's wrong with the iPad minis?

    I have an iPad mini and it works great, so do many other people.
    Is it possible your daughter abused the device?   If it gets dropped, even in a damage proof case, it is a shock to the iPad.   Most survive, but if it happens often, it might be a problem.
    Charging often, not completely, leaving in charger while in use a lot?
    Leaving the iPad in a hot car, or freezing the iPad?

  • Downloaded thunderbird 31 now my e-mail doesn't work. what's wrong?

    I downloaded Thunderbird 31 on 10/16/14 and the next day my e-mail did not work. So what is wrong?

    Your '''Installed Plug-ins'' list in '''''More system details...''''' to the right of your posting doesn't show Flash is installed for Firefox. <br />
    Do you have that plugin enabled or disabled?<br />
    Look in Tools > Addons > Plugins to see.
    Or did you download it and not actually install it?

  • Just installed Lion.  MNow my Microsoft Office suite won't work  What's wrong

    I just installed Lion.  Now my Microsoft Office Suite won't work.  What's wrong ??

    If you had used the search box in the upper right of this page you could have answered this question on your own.
    You have a few options: restore back to Snow Leopard from the backup you made before you installed Lion; upgrade to Office for Mac 2011; install Pages from the Mac App Store; use TextEdit; install one of the many open source Office replacements that can found.

Maybe you are looking for

  • Garageband for iPad and iPhone using Windows 7

    Hi, I'm new to GarageBand. I have an iPhone and an iPad. How can I copy a garageband project that I created on one device to the other device? Also, I use Windows 7. If I use the Save to... button in iTunes, I get to save a file, but when I try to us

  • How to merge cells in excel using X++ in AX 2009

     Hi all,  How to merge cells in excel using X++ in AX 2009?  for example i have 3 cells (A3:C3) i need to merge this 3 cells using X++ can any one sujjest please Thanks in advance

  • Form for ESI

    Hello All, Can anyone tell me what is the new form for ESI ? Is it not Form 6 and Form 7 ? Regards Vijay

  • Having trouble reconnecting render files

    Hi- I recently had to move a project from one hard drive to another, and although all the files are relatively in the same hierarchy (only the drive itself has changed) when I load the project in it shows almost the entire timeline needing rendering,

  • Applet ServerSocket SecurityException

    SecurityExceptionEx[Host]: cannot access 11110 My applet is signed. I use netscape security: PrivilegeManager.enablePrivilege("UniversalConnect"); PrivilegeManager.enablePrivilege("UniversalListen"); PrivilegeManager.enablePrivilege("UniversalAccept"