Write a class that verifies that a password meets

Assignment Help Computer Engineering
Reference no: EM132105042

This is the problem:

Imagine you are developing a software package for Ama/tHi.com 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 program as follows:

import java.util.Scanner;

public class Password { public static void main(String [] args)

{ String input; boolean hasUpperLetters = false;

boolean hasLowerLetters = false;

boolean hasDigits = false;

boolean hasSomethingElse = false;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter a password: ");

input = keyboard.nextLine();

int passLength = input.length();

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

char c = input.charAt(i);

if (Character.isUpperCase(c))

hasUpperLetters= true;

else if (Character.isLowerCase(c))

hasLowerLetters=true;

else if (Character.isDigit (c))

hasDigits = true;

else hasSomethingElse = true; }

if (hasUpperLetters && hasDigits && hasLowerLetters && !hasSomethingElse && (passLength >=6)) {

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

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

}

}

}

The algorithm is correct and runs correctly, BUT, our teacher wants us to have methods in the program, methods that "returns" values, so that the program is more efficient.

Can someone help me please?

Reference no: EM132105042

Questions Cloud

Write an lp for the mst problem : Write an LP for the MST problem, which enforces the constraint that at least one edge is selected from every cut.
Exploitation of labor and resources : What is meant by the concept of fair trade referencing to the exploitation of labor and resources?
What is the net operating income for the month : I do not know where to go after this?? What is the net operating income for the month under absorption costing?
What is the company margin of safety in dollars : What is the company's margin of safety in dollars?
Write a class that verifies that a password meets : 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.
How are the large losses related to fixed costs : How are the large losses related to fixed costs? Identity a way that John can turn potential fixed costs into variable costs.
The command line argument implement in python : The StackMachine class should have eight member functions: push, pop, add, sub, mul, div, mod and the constructor.
Purchasing power of money in the us : Who is responsible for sustaining the purchasing power of money in the US?
Npv estimated using cash flows : Would it expected that the NPV based on net revenue/income to be greater or lesser than the NPV estimated using cash flows?

Reviews

Write a Review

Computer Engineering Questions & Answers

  What is the total fertilizer use in honduras

What is the total fertilizer use in Honduras (metric tons) What is the average application per cropped area (100 grams per hectare of arable land) Compare this to fertilizer use per cropped area in the US

  What is essential address field width

What is essential address field width

  How web analytics has changed over the years

In 3-4 page APA formatted paper, discuss how web analytics has changed over the years. What should it look like in the future? What do you see as the biggest.

  Describe an implementation of the methods of a binary tree

Describe an implementation of the methods of a binary tree with this data structure and analyze the time complexity for these methods.

  Will hacking and breaches become more predominant

As the "Internet of Things" or as some are calling it "The Internet of Everything" evolves more and more, what do you see as the emerging technology.

  Write container class objects with overloaded operators

CSCI251/851 Advanced Programming- Write container class objects with overloaded operators and Implement programs incrementally to minimise debugging.

  How the "right" database design can rarely be decided

The "right" database design can rarely be decided on the basis of normalization principle alone. Do you agree or disagree? explain.

  Design a two-level circuit

Design a two-level circuit that adds 3 to each BCD digit input to it. Implement this circuit using half- and full adders. Compare the complexity and speed.

  Identify the systems in the organization

Identify the systems in the organization (i.e., the type and number of computer systems and operating systems use, along with top-level view of infrastructure).

  What are the two types of decision structures in sql

What are the two types of decision structures in PL/SQL? How can flowcharts assist developers? What happens when a CONSTANT option is set in a variable declaration?

  How many states does this mechine have

A state mechine transitions bsed on a single bit input. This mechine is looking for a simple pattern in that input, 1001. upon seeing 1001 it should outout.

  Write down problem on strings in java

Write down problem on strings in java

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd