Question

In: Computer Science

Imagine you are developing a software package for an online shopping site that requires users to...

Imagine you are developing a software package for an online shopping site that requires users to enter their own passwords. Your software requires that users' passwords meet the following criteria: The password should be at least six characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. Write a class that verifies that a password meets the stated criteria. Demonstrate the class in a program that allows the user to enter a password and then displays a message indicating whether it is valid or not.

I wrote the following code and I am receiving errors, can someone debug this?

import java.util.Scanner;

class Main {

public static void main (String []args)

{

String password; // to hold input entered by the user

boolean hasupperletters = false;

boolean haslowerletters = false;

boolean hasdigits = false;

boolean wronginput = false;

//create a scanner object and ask for input.

Scanner keyboard = new Scanner(System.in);

System.out.print("Create your password");

password = keyboard.nextLine();

int passlength= password.length();

//loop to go through all characters in the password String

for (int i = 0; i < passLength; i++){

char c = input.charAt(i);

//check for at least one uppercase character

if(Character.isUpperCase(c))

hasupperletters = true;

//check for at least one lowercase character

else if (Character.isLowerCase(c))

haslowerletters=true;

//check for at least one digit

else if(Character.isDigit(c))

hasdigits = true;

}

//check for correctly formatted password

if(hasupperletters && hasdigits && haslowerletters && !wronginput && (passlength>=6))

{

System.out.println("Password is correctly formatted");

}

else

{

System.out.println("Password is not correctly formatted");

}

}

}

Solutions

Expert Solution

Explanation:

Here is the corrected code which takes the password, checks for uppercases, lowercases and digits and then prints whether the password is satisfactory or not.

Code:

import java.util.Scanner;

class Main {

public static void main (String []args)

{

String password; // to hold input entered by the user

boolean hasupperletters = false;

boolean haslowerletters = false;

boolean hasdigits = false;

boolean wronginput = false;

//create a scanner object and ask for input.

Scanner keyboard = new Scanner(System.in);

System.out.print("Create your password");

password = keyboard.nextLine();

int passlength= password.length();

//loop to go through all characters in the password String

for (int i = 0; i < passlength; i++){

char c = password.charAt(i);

//check for at least one uppercase character

if(Character.isUpperCase(c))

hasupperletters = true;

//check for at least one lowercase character

else if (Character.isLowerCase(c))

haslowerletters=true;

//check for at least one digit

else if(Character.isDigit(c))

hasdigits = true;

}

//check for correctly formatted password

if(hasupperletters && hasdigits && haslowerletters && !wronginput && (passlength>=6))

{

System.out.println("Password is correctly formatted");

}

else

{

System.out.println("Password is not correctly formatted");

}

}

}

output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

You are developing a software package for an online shopping site that requires users to enter...
You are developing a software package for an online shopping site that requires users to enter their own passwords. Your software requires that users' passwords meet the following criteria: ● The password should be at least six characters long. ● The password should contain at least one uppercase and at least one lowercase letter. ● The password should have at least one digit. Write a method that verifies that a password meets the stated criteria. Use this method in a...
You are developing a software package for an online shopping site that requires users to enter...
You are developing a software package for an online shopping site that requires users to enter their own passwords. Your software requires that users' passwords meet the following criteria: ● The password should be at least six characters long. ● The password should contain at least one uppercase and at least one lowercase letter. ● The password should have at least one digit. Write a method that verifies that a password meets the stated criteria. Use this method in a...
Imagine you are developing a software package that requires users to enter their own passwords. Your...
Imagine you are developing a software package that requires users to enter their own passwords. Your software requires that users' passwords meet the following criteria: The password should be at least six characters long. The password should be at least one uppercase and at least one lowercase letter. The password should have at least one digit. Write a program that asks for a password then verifies that it meets the stated criteria. If it doesn't, the program should display a...
Imagine you are developing a software package that requires users to enter their own passwords. Your...
Imagine you are developing a software package that requires users to enter their own passwords. Your software requires that user’s passwords meet the following criteria: 1. The password should be at least six characters long. 2. The password should contain at least one uppercase and at least one lowercase letter. 3. The password should have at least one digit. Write a program that asks for a password and then verifies that it meets the stated criteria. If it doesn’t, the...
Early in 2021, the Excalibur Company began developing a new software package to be marketed. The...
Early in 2021, the Excalibur Company began developing a new software package to be marketed. The project was completed in December 2021 at a cost of $102 million. Of this amount, $68 million was spent before technological feasibility was established. Excalibur expects a useful life of five years for the new product with total revenues of $170 million. During 2022, revenue of $51 million was recognized. Required: 1. Prepare a journal entry to record the 2021 development costs. 2. Calculate...
Imagine you are writing a program to manage a shopping list. Each shopping list item is...
Imagine you are writing a program to manage a shopping list. Each shopping list item is represented by a string stored in a container. Your design requires a print function that prints out the contents of the shopping list. Using a vector to hold the shopping list items, write a print function to print out the contents of a vector of strings. Test your print function with a main program that does the following: Create an empty vector. Append the...
You are asked to review a nominal scale that identifies users versus non-users of an online...
You are asked to review a nominal scale that identifies users versus non-users of an online journal for primary school pupils. What is the most appropriate measure of central tendency? a. Range b. Mean c. Mode d. Median
This week you will write a program that mimics an online shopping cart . You will...
This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers for quantities -...
Developing software programs requires a systematic approach to problem solving and involves several steps. For a...
Developing software programs requires a systematic approach to problem solving and involves several steps. For a given problem statement – assuming the problem has a software solution – list and describe in your own words the steps that enable you to bring the software solution to life.
Imagine you are tasked with shopping for a space to open a new restaurant for your...
Imagine you are tasked with shopping for a space to open a new restaurant for your boss. You have found a target neighborhood for the restaurant with two options for location. One location is available for lease, and the other is available for purchase. How would you advise the owner of the business on the options for each restaurant location? What factors must be considered? Compare and contrast options for each location. Provide variables for the expectation of the future...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT