Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java program, add comments where possible please for thumbs up; A) i) b^2-4ac is called the discriminant of the quadratic equation. If it is positive,
Java program, add comments where possible please for thumbs up;
A)
i)
b^2-4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one real root. If it is negative, the equation has no real roots.
In a file called Ex4.java, write a program that prompts the user to enter double values for
a, b and c and then computes the discriminant. Your program should then test the value of the discriminant. It should compute and then display both roots if the discriminant is positive, or the single root if the discriminant is zero. For negative discriminants, it should display the message 'The equation has no real roots'.
Note that you can use Math.sqrt to compute the square root.
ii)
In a file called Ex5.java, write a program that checks password validity. Your program should read the user's chosen password into a String variable, using the nextLine method of Scanner to do this.
Your program should print "Password is too short" if the string contains fewer than 8 characters; otherwise, it should count and then display the numbers of uppercase characters, lowercase characters, digits and whitespace characters in the password.
After displaying the counts, your program should print "Password is OK" if the password satisfies the rules and "Password is invalid" if it does not. The rules used here are that passwords must contain at least 1 uppercase character, at least 1 lowercase character, at least 1 digit, and no whitespace characters at all.
To test characters in the password, you can use various static methods of the Character class - e.g., Character.isDigit().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started