Question
Flight status can be notified by the passengers by logging in to the Air Line web page. If you are planning for an international trip.
Flight status can be notified by the passengers by logging in to the Air Line web page. If you are planning for an international trip. The Flight status will give complete information about the flight each and every minute. By just having this feature it is easy to check the flight status, which is accessible from anywhere. Even though flight arrival and departure time information on the website is accurate, changes in weather can delay or reschedule a flight. So the official website will provide the proper status. By which the journey becomes more comfortable. So to get the complete details we have to log in to the website, there is a username and password to enter into the website. If the password does not match the given constraint(All the characters should be in Upper Case), it would display "Incorrect Password". Else, it would display "Bon Voyage". So help them to automate the above process by writing a Java program, which will throw a user-defined exception "IncorrectPasswordException".
Partial code is given to do the above task.
---------------------------------------------------------------------------------
public class IncorrectPasswordException{
// Fill the code
}
--------------------------------------------------------------------------------------
import java.util.*;
public class UserInterface {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter User Name");
String userName=sc.next();
System.out.println("Enter Password");
String password= sc.next();
// Fill the Code
}
}
--------------------------------------------------------------------------------------------
public class Validator {
public static boolean validatePassword(String password) throws IncorrectPasswordException
{
boolean flag = false;
char p[]=password.toCharArray();
int count=0;
for(char i:p)
{
if(Character.isUpperCase(i))
count++;
}
if (count==p.length){
flag=true;
}
else{
//Fill the code
}
return flag;
}
}
------------------------------------------------------------------------------------------------------
In the Validator class, you are provided with the method, public static boolean validatePassword(String password).
The logic for validating the password is already given as part of the partial code skeleton. Complete the rest of the code as below.
If the password meets the requirement, this method returns true.
If the password does not meet the requirement, this method should throw a user-defined exception "IncorrectPasswordException".
Use the appropriate Constructor in Exception class to set the error message.
From the main method invokes the validatePassword method and handles the exception and print the appropriate message.
Sample input 1:
Enter User Name
Daniel
Enter Password
Daniel
Sample output 1:
Incorrect Password
Sample input 2:
Enter User Name
Samuel
Enter Password
CATHY
Sample output 2:
Bon Voyage
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