
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
(Intro to Java)
AVOID USING BREAKS. DO NOT USE BREAKS
New Password
- In this assignment, you will write a short program to allow a user to create a new password, and then login with this password.
- You will need to use both if-else and for loops.
- The program will begin by prompting the user to enter a new password. The program will then ask the user to confirm the password.
- From there, one of several possible scenarios will occur.
1. The second password the user types does not match the first:
- In this case, allow the user one more try by asking them to confirm the password again
Enter your new password: abc123
Enter your new password again: abc124
Sorry! Those passwords don't match.
Please try again
Enter your new password again: abc123
Password confirmed. Logging out...
Enter your new password again: abc124
Sorry! Those passwords don't match.
Please try again
Enter your new password again: abc123
Password confirmed. Logging out...
- Should the user type the password incorrectly twice, the program should exit.
Enter your new password: abc123
Enter your new password again: abc124
Sorry! Those passwords don't match.
Please try again
Enter your new password again: abc124
Sorry! Those passwords don't match.
Goodbye!
Enter your new password again: abc124
Sorry! Those passwords don't match.
Please try again
Enter your new password again: abc124
Sorry! Those passwords don't match.
Goodbye!
2. The second password matches the first (either on the first or second attempt):
- In this case, log the user out, and then ask the user to login using their new password
Enter your new password: abc123
Enter your new password again: abc123
Password confirmed. Logging out...
Enter your password:
Enter your new password again: abc123
Password confirmed. Logging out...
Enter your password:
- Give the user exactly 5 tries to type in their new password correctly (use a for loop) - reporting the number of tries remaining, for each attempt:
- Should the user type the password correctly within the 5 tries, log the user in
Password confirmed. Logging out...
Enter your password: abc124
Invalid password. You have 4 more tries.
Enter your password: abc125
Invalid password. You have 3 more tries.
Enter your password: abc123
Welcome! You are now logged in.
Enter your password: abc124
Invalid password. You have 4 more tries.
Enter your password: abc125
Invalid password. You have 3 more tries.
Enter your password: abc123
Welcome! You are now logged in.
- Otherwise, should the user not type the password correctly within 5 tries, exit the program.
Password confirmed. Logging out...
Enter your password: ab
Invalid password. You have 4 more tries.
Enter your password: abc
Invalid password. You have 3 more tries.
Enter your password: ab3
Invalid password. You have 2 more tries.
Enter your password: abc1
Invalid password. You have 1 more tries.
Enter your password: abc12
Invalid password. You have 0 more tries.
Goodbye!
Enter your password: ab
Invalid password. You have 4 more tries.
Enter your password: abc
Invalid password. You have 3 more tries.
Enter your password: ab3
Invalid password. You have 2 more tries.
Enter your password: abc1
Invalid password. You have 1 more tries.
Enter your password: abc12
Invalid password. You have 0 more tries.
Goodbye!
Starter Code: Copy and paste the below starter code into a file NewPasswords.java
/**
* @author
* @author
* CIS 36A
*/
import java.util.Scanner;
public class NewPasswords {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String password;
String passwordConfirm;
final int MAX_TRIES = 5;
System.out.print("Enter your new password: ");
password = input.next();
* @author
* @author
* CIS 36A
*/
import java.util.Scanner;
public class NewPasswords {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String password;
String passwordConfirm;
final int MAX_TRIES = 5;
System.out.print("Enter your new password: ");
password = input.next();
//fill in here
if (//fill in test condition here){
System.out.println("\nSorry! Those passwords don't match.\nPlease try again");
//fill in here
}
if (password.equals(passwordConfirm)) {
System.out.println("\nPassword confirmed. Logging out...\n");
for (//fill in here... hint count DOWN) {
System.out.print("Enter your password: ");
if (password.equals(passwordConfirm)) {
System.out.println("\nPassword confirmed. Logging out...\n");
for (//fill in here... hint count DOWN) {
System.out.print("Enter your password: ");
//fill in here
if (//fill in here)) {
System.out.println("\nWelcome! You are now logged in.");
i = 0; //What does this line do? Make sure you understand
} else {
System.out.print("Invalid password.);
System.out.println("\nWelcome! You are now logged in.");
i = 0; //What does this line do? Make sure you understand
} else {
System.out.print("Invalid password.);
//fill in here
}
}
} else {
System.out.print("Sorry! Those passwords don't match.");
}
System.out.println("\nGoodbye!");
input.close();
}
}
}
} else {
System.out.print("Sorry! Those passwords don't match.");
}
System.out.println("\nGoodbye!");
input.close();
}
}
- Fill in the missing parts of the starter code where the comments indicate
- When your program works identically to the sample output below, submit it to Canvas.
Sample Output:
Enter your new password: abc123Enter your new password again: abc123
Password confirmed. Logging out...
Enter your password: abc123
Welcome! You are now logged in.
Goodbye!
Sample Output:
Enter your new password: abc123
Enter your new password again: abc124
Sorry! Those passwords don't match.
Please try again
Enter your new password again: abc123
Password confirmed. Logging out...
Enter your password: abc124
Invalid password. You have 4 more tries.
Enter your password: abc1265
Invalid password. You have 3 more tries.
Enter your password: abc124
Invalid password. You have 2 more tries.
Enter your password: abc12
Invalid password. You have 1 more tries.
Enter your password: abc123
Welcome! You are now logged in.
Goodbye!
Enter your new password again: abc124
Sorry! Those passwords don't match.
Please try again
Enter your new password again: abc123
Password confirmed. Logging out...
Enter your password: abc124
Invalid password. You have 4 more tries.
Enter your password: abc1265
Invalid password. You have 3 more tries.
Enter your password: abc124
Invalid password. You have 2 more tries.
Enter your password: abc12
Invalid password. You have 1 more tries.
Enter your password: abc123
Welcome! You are now logged in.
Goodbye!
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Similar questions
- (PYTHON GUI - Tkinker) Write a Python program GUI that reads the following information from user, and prints a payroll statement: Employee’s name (e.g., Smith) Number of hours worked in a week (e.g., 10) Hourly pay rate (e.g., 60.75) ATO tax withholding rate (e.g., 30%) Medicare Levy rate (e.g., 2%)arrow_forward(True/False): The PROC directive begins a procedure and the ENDP directive ends aprocedure.arrow_forward(Find the two highest scores)Write a program that prompts the user to enter the number of students and each student’s name and score, and displays the name and score of the student with the highest score and the student with the second-highest score.Sample RunEnter the number of students: 5Enter a student name: SmithEnter a student score: 60Enter a student name: JonesEnter a student score: 96Enter a student name: PetersonEnter a student score: 85Enter a student name: GreenlawEnter a student score: 98Enter a student name: ZhangEnter a student score: 95Top two students:Greenlaw's score is 98.0Jones's score is 96.0arrow_forward
- Choose the correct answer: Statements in while loop will be executed at least once. Statements in do...while loop will be executed at least once. Statements in for loop will be executed at least once. Statements in any loop will always be executed at least once.arrow_forward(True/False): The USES operator only generates PUSH instructions, so you must code POPinstructions yourself.arrow_forward(Slope of a line) Write a program that prompts the user to enter the coordinates of two points (x1, y1) and (x2, y2), and displays the slope of the line that connects the two points. The formula of the slope is (y2 - y1)/(x2 - x1).arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY