Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gnarly;
- import java.util.Scanner;
- public class Main {
- private static final Scanner scanner = new Scanner(System.in);
- private static final String USERNAME = "Gnarly";
- private static final String PASSWORD = "123";
- private String username;
- private String password;
- public static void main(String[] args) {
- new Main();
- }
- public Main() {
- askForUsername();
- askForPassword();
- welcomeUser();
- }
- private void askForUsername() {
- do {
- System.out.print("Type your username : ");
- username = scanner.nextLine();
- if (!username.equalsIgnoreCase(USERNAME)) {
- System.out.println("You have entered an invalid username. Try again.");
- }
- } while (!username.equalsIgnoreCase(USERNAME));
- }
- private void askForPassword() {
- do {
- System.out.print("Type your password : ");
- password = scanner.nextLine();
- if (!password.equalsIgnoreCase(PASSWORD)) {
- System.out.println("You have entered an invalid password. Try again.");
- }
- } while (!password.equalsIgnoreCase(PASSWORD));
- }
- private void welcomeUser() {
- System.out.println("Hello, " + username);
- System.out.println("Type .changepassword to change your password.");
- String command = scanner.nextLine();
- if (command.equalsIgnoreCase(".changepassword")) {
- do {
- System.out.println("Please type in your new password : ");
- String newPassword = scanner.nextLine();
- System.out.println("Please retype your new password : ");
- String newPasswordVerify = scanner.nextLine();
- if (newPassword.equalsIgnoreCase(newPasswordVerify)) {
- password = newPassword;
- System.out.println("Your new password has been set.");
- } else {
- System.out.println("The two passwords you entered didn't match. Try again.");
- }
- } while (password.equalsIgnoreCase(PASSWORD));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement