Instructions Objectives: Use a while loop Use multiple loop controlling conditions Use a boolean method Use the increment operator Extra credit: Reuse earlier code and call two methods from main    Details: This assignment will be completed using the Eclipse IDE. Cut and paste your code from Eclipse into the Assignment text window.  This is another password program. In this case, your code is simply going to ask for a username and password, and then check the input against four users. The program will give the user three tries to input the correct username-password combination. There will be four acceptable user-password combinations:  alpha - alpha1 beta - beta1 gamma - gamma1 delta - delta1 If the user types in one of the correct username-password combinations, then the program will output: “Login successful.” Here are a couple of example runs  (but your code needs to work for all four user-password combinations): Username: beta Type your current password: beta1 Login successful. Username: delta Type your current password: delta1 Login successful. If the user types the wrong username-password combination, then the program will output “Username or password incorrect” and give them another chance. Your program should give them three chances. The first two times the program will also output “Try again,” but on the third unsuccessful try it will output “Too many attempts” and end. Here is an example of what your program should output when there are three unsuccessful login attempts: Username: mary Type your current password: secret Username or password incorrect. Try again. Username: alpha Type your current password: supersecret Username or password incorrect. Try again. Username: angela Type your current password: beta1 Username or password incorrect. Too many attempts. Here are two examples of initial failed logins followed by a successful login: Username: alpha Type your current password: beta1 Username or password incorrect. Try again. Username: alpha Type your current password: alpha1 Login successful. Username: alpha Type your current password: beta Username or password incorrect. Try again. Username: mary Type your current password: beta1 Username or password incorrect. Try again. Username: gamma Type your current password: gamma1 Login successful. In order to make this happen, ask for the username and password inside a while loop in the main method. Do the checks for a correct combination, and remain in the loop as long as the combinations are not correct – but only for three iterations. Use the increment operator to count the number of attempts. It is going to be tricky to print out the right messages for different situations. Instead of checking all the username-password combinations in the main method, write a method called userPasswordMatch that takes a username and password as input. Send the username and password values from the main method to userPasswordMatch. If the combination matches one of the four acceptable user-password combinations, userPasswordMatch should return true, otherwise it should return false. (A reason to do this is to make it possible to add new users without touching the main method.) (Hint: You can use the return value of userPasswordMatch to control the while loop.) Don’t do unnecessary tests, i.e. if a test is successful, don’t continue to do more tests.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Instructions

Objectives:

  • Use a while loop
  • Use multiple loop controlling conditions
  • Use a boolean method
  • Use the increment operator
  • Extra credit: Reuse earlier code and call two methods from main 

 

Details:
This assignment will be completed using the Eclipse IDE. Cut and paste your code from Eclipse into the Assignment text window. 

This is another password program. In this case, your code is simply going to ask for a username and password, and then check the input against four users. The program will give the user three tries to input the correct username-password combination.

There will be four acceptable user-password combinations: 

  • alpha - alpha1
  • beta - beta1
  • gamma - gamma1
  • delta - delta1

If the user types in one of the correct username-password combinations, then the program will output: “Login successful.” Here are a couple of example runs  (but your code needs to work for all four user-password combinations):

Username: beta
Type your current password: beta1
Login successful.

Username: delta
Type your current password: delta1
Login successful.

If the user types the wrong username-password combination, then the program will output “Username or password incorrect” and give them another chance. Your program should give them three chances. The first two times the program will also output “Try again,” but on the third unsuccessful try it will output “Too many attempts” and end.

Here is an example of what your program should output when there are three unsuccessful login attempts:

Username: mary
Type your current password: secret
Username or password incorrect.
Try again.
Username: alpha
Type your current password: supersecret
Username or password incorrect.
Try again.
Username: angela
Type your current password: beta1
Username or password incorrect.
Too many attempts.

Here are two examples of initial failed logins followed by a successful login:

Username: alpha
Type your current password: beta1
Username or password incorrect.
Try again.
Username: alpha
Type your current password: alpha1
Login successful.

Username: alpha
Type your current password: beta
Username or password incorrect.
Try again.
Username: mary
Type your current password: beta1
Username or password incorrect.
Try again.
Username: gamma
Type your current password: gamma1
Login successful.

In order to make this happen, ask for the username and password inside a while loop in the main method. Do the checks for a correct combination, and remain in the loop as long as the combinations are not correct – but only for three iterations. Use the increment operator to count the number of attempts. It is going to be tricky to print out the right messages for different situations.

Instead of checking all the username-password combinations in the main method, write a method called userPasswordMatch that takes a username and password as input. Send the username and password values from the main method to userPasswordMatch. If the combination matches one of the four acceptable user-password combinations, userPasswordMatch should return true, otherwise it should return false. (A reason to do this is to make it possible to add new users without touching the main method.) (Hint: You can use the return value of userPasswordMatch to control the while loop.) Don’t do unnecessary tests, i.e. if a test is successful, don’t continue to do more tests. 

 

Extra credit (+10 points):

If the user successfully logs in, then let them change their password like last week. If they successfully log in, then ask them twice for a new password. Work last week’s code into this week’s program, and reuse the passwordChecker method from last week (fix it if necessary) using the same criteria for acceptable passwords. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education