Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can someone help me add methods into my code?  RSS feed

 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I had to write a code to encrypt a password the user inputs which I was able to do. But now I have to add methods and make a driver class which I am terrible at. Whenever I try to the file with all the code can't pick up the variables I set in the driver class and it becomes a giant disaster. So can someone give me the basics on how to add a method and a driver class into a code? Every part of the code that has // has to be its own method. Here is the code I am trying to add methods into



Sorry for asking such an open ended question but I have no idea where to even begin.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still unable to understand your problem.. Can you please elaborate?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm understanding correctly, you want to do something like this:
 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:If I'm understanding correctly, you want to do something like this:


Exactly but whenever I try something like that I get errors so I assumed I was doing it wrong. Here is the part of my new code with the method I tried to put in.



and here are the errors I get

[line: 11]
Error: illegal start of expression
[line: 11]
Error: ';' expected
[line: 11]
Error: ';' expected

So what should I do to fix these errors?
 
Liutauras Vilda
Marshal
Posts: 4638
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Sing wrote:So what should I do to fix these errors?
There are few things.

1st - you cannot declare method within method, so you have to close your main method, then declare another.
2nd - you cannot call non static method in static method.

This sort of example could help you only for a quick little practise programs. For better practises search for faq "Main Is A Pain".

Example to solve 1st and 2nd mentioned points.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!