Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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?

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93092511

Have any Question?


Related Questions in Computer Engineering

Question 1 complete the lab 9-5 programming challenge 1 --

Question: 1. Complete the Lab 9-5, "Programming Challenge 1 -- Going Green," of Starting Out with Programming Logic and Design. Note: You are only required to create the flowchart for this activity; however, notice how t ...

Question you need to research the topic and discuss the

Question: You need to research the topic and discuss the topic in at least 400-500 words with references. A post without a reference will not count as a discussion. What is text mining and what is the purpose of it? Give ...

Question creating an interface please respond to the

Question: "Creating an Interface" Please respond to the following: • Imagine you are managing a design project that will create an interface for automobile mechanics. The interface would be used by the mechanics to look ...

Analyse two of the three technologies provided focus

Analyse two of the three technologies provided (focus virtualisation, cloud computing and green computing). Summarise what each of your two selected technologies is, and what the technology does. Explain what improvement ...

Describe the definition of ransomware and what is wannacry

Describe the definition of ransomware. And what is wannacry threat?

Question sally averages 5 strokes a hole when she plays

Question: Sally averages 5 strokes a hole when she plays golf. One day, she took 40 strokes to complete the first nine holes. Her partner conjectured that she would probably regress to the mean and take 50 strokes to com ...

Why would a policy of re-importation of prescription drugs

Why would a policy of re-importation of prescription drugs be ineffective?

In reconnaissance provide three different methods or means

In Reconnaissance Provide three different methods or means to locate information about your target. What sorts of information would you expect to obtain using each source? What might you use the information obtained from ...

Smartphones have become an important part daily life

Smartphones have become an important part daily life, including how we communicate in business. Mobile device security is emerging as one of top targets for cybercriminals. Using Microsoft Word, write a 400 word paper us ...

Subject digital securitybesides legal factors what are

Subject : Digital Security Besides legal factors, what are some of other important factors that need to be seriously considered when the cloud computing and service company(assuming) you work for decides to extend busine ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As