Professional Documents
Culture Documents
Untitled
Untitled
Question 1
Create your own exception called InvalidDirectionException it should display an
message called “You are going in wrong direction”. Your code should get two
input’s which is HouseDirection and GpsLocation.
If the mail entered is doesn’t exist on the list of valid mail id’s, then the output is
“New user”.
If the mail entered is exist on the list of valid mail id’s, an exception is thrown called
CheckUserMailException.
Question 2
Sample Input: Sample Output:
ironman@gmail.com CheckUserMailException: Email
godofthunder@gmail.com Already Registered
captainamerica@gmail.com
nicolasfury@gmail.com
hulk@gmail.com
godofthunder@gmail.com
1 import java.util.*;
2 class CheckUserMailException extends Exception
3 {
4 public CheckUserMailException(String message)
5 {
6 super(message);
7 }
8 }
9 class RegistrationService
10 {
11 public void validateEmail(List registeredEmails,String email) throws CheckUserMailException
12 {
13 if (registeredEmails.contains(email))
14 {
15 throw new CheckUserMailException("Email Already Registered");
16 }
17 else
18 System.out.print("New user");
19 }
20 }
21
22
1 public class RegistrationServiceClient {
2 public static void main(String[] args) {
3 Scanner sc = new Scanner(System.in);
4 String str[]= new String[5];
5 for(int i=0;i<5;i++)
6 {
7 str[i]=sc.next();
8 }
9 String mail = sc.next();
10 List<String> registeredEmails = Arrays.asList(str);
11 RegistrationService service = new RegistrationService();
12 try{
13 service.validateEmail(registeredEmails, mail);
14 }
15 catch (CheckUserMailException e) {
16 System.out.print(e);
17 }
18 }
19 }
20
21
22
Question 3
Create your own exception called IncorrectPinException it should display an
message called “Please Try again”. Your code should get two input from the user
which are setpin and pin.
If the setpin matches with the pin, then the output is “Mobile Unlocked”.
If the setpin doesn’t matches with the pin, an exception is thrown called
IncorrectPinException.
Question 3
Sample Input1: Sample Output1:
475 IncorrectPinException: Please Try
485 again
Get size of an array ,array elements and the element at which index need be fetched
in the array from the user.
Question 4
If the given index is with in the range, it will display the element.
If the user forget to enter the password, it will throw an NullPointerException and
this exception thrown by using your own exception named
EnteryourPasswordException.
Question 5
Sample Input: Sample Output:
No input Exception in thread "main"
EnteryourPasswordException: Kindly Enter the
Password
at LoginPage.CheckPassword(Main.java:26)
at Main.main(Main.java:35)
Caused by: java.lang.NullPointerException
at LoginPage.CheckPassword(Main.java:18)
... 1 more
1 import java.util.Scanner;
2 class EnteryourPasswordException extends RuntimeException
3 {
4 public EnteryourPasswordException(String message, Throwable cause)
5 {
6 super(message, cause);
7 }
8 }
9 class LoginPage
10 {
11 public void CheckPassword(String Password)
12 {
13 if(Password.length()==0)
14 {
15 Password = null;
16 }
17 try {
18 if(Password.equals("Thanos"))
19 System.out.print("Successfully Logged in");
20 else
21 System.out.print("Invalid Password");
22 }
1 catch (NullPointerException e)
2 {
3 throw new EnteryourPasswordException("Kindly Enter the Password", e);
4 }
5 }
6 }
7 public class Main {
8 public static void main(String[] args) {
9 Scanner sc = new Scanner(System.in);
10 String Password = sc.nextLine();
11 LoginPage login = new LoginPage();
12 login.CheckPassword(Password);
13 }
14 }
15
16
17
18
19
20
21
22
THANK YOU