Hi all! I'm new to Java and programming and am taking my first programming course in college. No, this isn't homework help as I've completed that portion of the assignment. I'd simply like to do some extra coding, etc., to try to learn more. In other words, I'd like to go above and beyond. Anyway, I was hoping some of you experienced programmers could give me some pointers and or suggestions. Below is part of the program that we had to write. The teacher provided the code. We just had to type it in and change some things around to reflect our own made up company name and products. I was interested in adding my own method to the code that simply masks the last two characters of the user's password. So, below is my main method and the maskPassword method that I created. Did I implement the maskPassword method correctly? Even if it is correct, is it really the "right" way to do something like this? Initially, I named the method public void String mask password, but was getting errors along the lines of cannot use void with static something or another. I did some research and came to the conclusion that I needed to create an instance of the my class, so I added the code to create an instance of CompuTech, then did the string manipulation. Any feedback here would be very much appreciated!
public class CompuTech { public static void main(String[] args) { CompuTech instance = new CompuTech(); .....program displays a few input boxes and messages, etc. // build the various output strings nameOutputMsg = "Welcome " + customerName + "!\n"; returnOutputMsg = "Your login is: " + userid + "/" + [B]instance.maskPassword(password)[/B] + ".\n\n"; greetingOutputMsg = "Thank you for visiting CompuTech!\n"; // this combines all the output strings and assigns them to one variable outputMsg = nameOutputMsg + returnOutputMsg + greetingOutputMsg; // displays the complete output string JOptionPane.showMessageDialog( null, outputMsg ); System.exit(0); } // end main // method to mask the last two characters of the password with asterisks private String maskPassword(String password){ // if password is at least two characters long, mask last two characters if (password.length() > 1) { password = password.substring(0, password.length() - 2) + "**"; } // password is only 1 character long, so just mask the one character else if (password.length() == 1) { password = password.substring(0, password.length() - 1) + "*"; } else { password = "non entered"; } return password; } // end maskPassword } // end Class CompuTech