944,216 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4657
  • Java RSS
Nov 23rd, 2004
0

missing return statement 106 and 123, any ideas??

Expand Post »
Im writing an encription program and it keeps saying their are 2 missing return statements :cry: , any ideas?


public class EncryptedMessage
{

public static final int NO_OF_LETTERS = 26; //a-z incl
public static final int NO_OF_NUMBERS = 10; //0-9 incl
public static final int NO_OF_CHARACTERS = NO_OF_LETTERS + NO_OF_NUMBERS;


private String message;
public static final char[][] cipherArray =
{{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'},
{'!','"','£','$','%','^','&','*','(',')','_','#','@',':',';','{','}','[',']','=','?','<','>','~','+','|','B','P','S','E','C','U','R', 'I','T','Y'}};

public EncryptedMessage()
{ message = ("");
}

public EncryptedMessage(Object o)
{ message = (String)o;
}

public EncryptedMessage(String s)
{ message = s;
}
public EncryptedMessage(int i)
{ message = Integer.toString(i);
}


public String encryptText()
{

//convert message to character array
char[] mess = message.toCharArray();
int len = mess.length;

//create a second array to store the encrypted text
char[] encrypted = new char[len];

//Get each cipher letter for each character and store in the character array
//outputText.
for(int i =0; i<=mess.length; i++)
{
encrypted[i]=crypt(mess[i]);
}

StringBuffer enText = new StringBuffer("");
//append character array to StringBuffer, convert to a String and trim off control characters
return ((enText.append(encrypted)).toString().trim());


}

public String decryptText()
{

//convert string to character array
char[] returnMess = message.toCharArray();
int messLen = returnMess.length;

//create a second array to store the encrypted text
char[] encrypted2 = new char[messLen];

//Get each cipher letter for each character and store in the character array
for(int i =0; i<=messLen; i++)
{
encrypted2[i]=decrypt(returnMess[i]);
}

StringBuffer enText = new StringBuffer("");
//append outputText to StringBuffer, convert to a String and trim off control characters
return ((enText.append(encrypted2)).toString().trim());


}



// All characters outside of the character subset should be left unencrypted.
public static char crypt(char c)
{
//look for the character in the top row of the cipher array
for(int i=0; i<=NO_OF_CHARACTERS;i++)
{
if(cipherArray[i][0]==c)
{
return cipherArray[0][i];
}
else
{
return c;
}
}
}

public static char decrypt(char c)
{
//look for the character in the bottom row of the cipher array
for(int i =0; i <=NO_OF_CHARACTERS;i++)
{
if(cipherArray[0][i]==c)
{
//return relevant encryted character or original character if not in character set
return cipherArray[i][0];
}
else
{
return c;
}
}

}


}


Thanx :lol:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fulmont99 is offline Offline
4 posts
since Nov 2004
Nov 23rd, 2004
0

Re: missing return statement 106 and 123, any ideas??

In both methods:
char crypt
char decrypt
You specify a char return type, but you are returning an char array type

char[] crypt
char[] decrypt
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
jerbo is offline Offline
84 posts
since Sep 2004
Nov 23rd, 2004
0

Re: missing return statement 106 and 123, any ideas??

Opps, I see you are returning char[][] not char []......change to char[][]
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
jerbo is offline Offline
84 posts
since Sep 2004
Nov 26th, 2004
0

Re: missing return statement 106 and 123, any ideas??

Quote originally posted by jerbo ...
Opps, I see you are returning char[][] not char []......change to char[][]

Is their any way i could return a single char to the calling program? :o
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fulmont99 is offline Offline
4 posts
since Nov 2004
Nov 26th, 2004
0

Re: missing return statement 106 and 123, any ideas??

not using a function that returns an array...
You can of course return an array that contains only 1 element.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 26th, 2004
0

Re: missing return statement 106 and 123, any ideas??

I must appoligize again. I was looking at your code while getting ready to go out the door.
In your code above, you are actually returning one characher:
return cipherArray[i][0];
So your return type would still be char, instead of char[][].

Sorry about that
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
jerbo is offline Offline
84 posts
since Sep 2004
Nov 30th, 2004
0

Re: missing return statement 106 and 123, any ideas??

ok im returning one single char, therefore their should be no problem. But i am still getting the missing return statement message.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fulmont99 is offline Offline
4 posts
since Nov 2004
Nov 30th, 2004
0

Re: missing return statement 106 and 123, any ideas??

Its ok guys, i got it. it was returning a missing return statement because i had it returning the values from within a for loop.

I just changed the return to a char outside the loop.

Thanx anywayz. :lol:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fulmont99 is offline Offline
4 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java editor
Next Thread in Java Forum Timeline: Reading in a file.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC