Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions: Create a program that will help online users set-up an account with a user name and password. The users will have 2 attempts at

Instructions: Create a program that will help online users set-up an account with a user name and password. The users will have 2 attempts at validating or confirming their entries. Use do-while loops to control a re-do of the account set-up and the user name entry. Use a for loop to control the password entry. The loops are nested. The do-while is better suited as the outer most loop. Look at the sample output for prompt, output messages, and spacing requirements. //There is no default username and password.. user creates their own and the first input of their username and password is compared with the second to ensure they match Use a sentinel-controlled do-while to control a re-do of the account set-up. Use a counter-controlled do-while to control the user name entry. Set the counter-control variable to 1 and decrement through zero, which constitutes your 2 attempts. Also set the counter-control variable of the for loop to 1 and decrement through zero. Declare it outside of the for loop along with all the other variable declarations at the beginning of main(). Make sure to set the counter-control variables to -1 when the userName and password are confirmed. Declare a boolean variable called successful and initialize it to false. Set it to true when the password is confirmed and set it to false when the user wants to start over. Print Invalid user name re-entry! 9 more attempt(s) left. where the 9 represents the number of attempts left for an invalid user name confirmation. You dont need to print the double quotes in the message. Print Invalid password re-entry! 9 attempt(s) left. when the password re-entry is incorrect and where the 9 represents the number of attempts left. You dont need to print the double quotes in the message. Use the String methods: equalsIgnoreCase() to test the user name: if(userName.equalsIgnoreCase(confirmUserName)) equals() to test the password: if(password.equals(confirmPassword)) Code System.exit(0) only once at the end of main

My coding is wrong but it is very close to what is being asked

import java.util.Scanner;

public class tofdNLE41 { public static void main(String[] args) { String userName = "tod";

String password = "doggie";

Scanner in = new Scanner(System.in);

int doCounter = 0; Scanner input = new Scanner(System.in);

int userNmAttmpts = 1, pwAttempts = 1; char redo =' '; boolean successful = false; do { System.out.printf("%nPlease enter user name: "); ++userNmAttmpts; String userNameInput = in.nextLine(); do { System.out.printf("%nPlease enter password: ", --pwAttempts); --pwAttempts; String password = in.nextLine(); if(userName.equalsIgnorCase(confirmUserName)) { userNmAttmpts = -1; for(; pwAttempts >=0; pwAttempts--) { if(password.equals(confirmPassword)) { pwAttempts = -1; successful = true; } else { } } } else { } userNmAttmpts--; }while(userNmAttmpts >=0); if(!succesful) { System.out.printf("%nDo you want to start over? \'Y\' or \'N\': "); redo = input.nextLine().charAt(0); succesful = false; userNmAttmpts = 1; pwAttmpts = 1; } else { redo = 'n'; } }while(Character.toUpperCase(redo) == 'Y'); System.exit(0); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago