Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class help with character replacing?

 
M. Mills
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have an assignment where I take input and search for and replace certain letters with others to create a code, and then I decode it. I'm confused about how to create create a loop to search for the letters. I know I use a if else statement inside the looping statement, but I don't know how to form it.

This is the file with the classes:



And here is the file that uses the classes:



Thank you so much!
[edit]Add code tags and change comments to /* */ type so as to fit width of screen. CR[/edit]

 
Henry Wong
author
Marshal
Pie
Posts: 21414
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has to be something like ag',r replaces v, but I always get "Unclosed character literal."


Something like what??? Not sure what you are trying to write here.

String encryptdSntnc = myCryptObj.encrypt(sntnc); This is the spot where I'm told that "encrypt() in Crypto cannot be applied to (java.lang.String)."


Your encrypt() method doesn't take parameters -- it is called with a single string parameter here.

String decryptdSntnc = myCryptObj.decrypt(encryptdSntnc); This is the other spot.


Your decrypt() method doesn't take parameters -- it is called with a single string parameter here.

Henry
 
M. Mills
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you mean by a single string parameter?
 
Henry Wong
author
Marshal
Pie
Posts: 21414
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M. Mills wrote:What exactly do you mean by a single string parameter?



Your code.... calls the encrypt method... right here...

String sntnc = kbReader.nextLine();
System.out.println("Original sentence = " + sntnc);

Crypto myCryptObj = new Crypto();
String encryptdSntnc = myCryptObj.encrypt(sntnc);


Notice that you pass it a single parameter? Named sntnc? And notice that it is a string? .... aka a single string parameter?

Henry
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please use code tags (read this FAQ) and break long comments into separate lines. I have edited your post, and you can see how much better it looks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic