Question #60897

Manish has realized the power of compounding. Since the days he started earning, he has diligently set aside a small corpus which he saves from his monthly salary and deposits in his bank account. Bank pays him interest every month. Manish is also a determined investor and refrains from withdrawing anything from this account because he now believes in power of compounding. Given investment corpus, fixed annual rate of interest and maturity period calculate the amount the Manish will end up saving at the end of his tenure.
1

Expert's answer

2016-07-25T13:51:02-0400

Answer on Question #60927, Programming & Computer Science

1. encrypt the information word by word.

2. use the last alphabetic character in each word as the key for encrypting that word.

3. consider the value of each alphabetic character as its alphabetic position i.e.

a=A=1

b=B=2

and so on

z=Z=26

1. for every word use the last alphabetic character in the world as the key.replace all the alphabetic character in the word with new alphabetic characters formed by subtracting the key value from each character.

2. key character(last alphabetic character in each word) should not be encrypted.

3. encryption should be performed only on alphabetic characters and not on non-alphabetic character such as digits or special character.

4. all alphabetic characters should be preserved as uppercase in their respective position but should be replaced with the new character.

Solution

I build 2 class: Main for I/O, and Encrypting for Function.


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Encrypting e = new Encrypting();
Scanner in = new Scanner(System.in);
String firststring = in.nextLine();
char [] myCharFirst = firststring.toCharArray();
System.out.println("Final String: " + e.encrypting(firststring));
}
}
public class Encrypting {
String encrypting (String myStr)
{
String FinalStr;
char [] myCharFirst = myStr.toCharArray();
char [] myCharFinal = new char[myStr.length()];
int LastNumber=0, nextNumber=0;
for(int i=0; i<myStr.length(); i++) {
if(i == myStr.length()) break;
nextNumber = getNumberOfLastWord(myCharFirst,LastNumber);
for(int j=LastNumber; j<nextNumber; j++)
{
if(myCharFirst[j]<123 && myCharFirst[j]>96) {
myCharFirst[j] = (char) (97+(myCharFirst[j]-myCharFirst[nextNumber-1]));
} else if(myCharFirst[j]<91 && myCharFirst[j]>64) {
myCharFirst[j] = (char) (-(myCharFirst[j]-myCharFirst[nextNumber-1])+96);
} else {
myCharFinal[j] = myCharFirst[j];
}
}
LastNumber = nextNumber + 1;
i = LastNumber;
}
FinalStr = new String(myCharFinal);
return FinalStr;
}
int getNumberOfLastWord(char[] myChar, int lastNumber)
{
int i = 0;
for (i = lastNumber; i < myChar.length; i++)
{
if (i > myChar.length) break;
if (myChar[i] == 32)
{
break;
}
}
return i;
}
}


Screen:

asddas 111 ASD

Final String: raoors 111 ASD

http://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS