Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- // Create an AccountSetup application
- public class AccountSetup {
- public static void main(String[] args) {
- // prompts the user for a user name and a password
- String username = read("Enter username? ");
- String password = read("Enter password? ", 8);
- // an appropriate message displayed
- System.out.printf("Account has been setup. The username: %s, Password: %s%n", username, password);
- }
- private static String read(String message) {
- System.out.print(message);
- Scanner kb = new Scanner(System.in);
- // The user name and password should be converted to all lowercase letters
- return kb.nextLine().toLowerCase();
- }
- private static String read(String message, int numberOfCharacter) {
- boolean done = false;
- String result = null;
- do {
- result = read(message);
- // until a password with at least eight characters is entered
- if (result.length() >= numberOfCharacter) {
- done = true;
- } else {
- // an appropriate message displayed
- System.err.println("Error: invalid value was entered.");
- }
- } while (!done);
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement