all details are attached
it should be simple
complete the code that are attached with if statements conditions for each question.
all details are attached Exercise No. (13)
Type: Individual exercise.
Description: This is an input validation coding exercise, as most software
product require input of data and such input step can be done in a way that
affect security negatively.
Tasks:
1. Write and execute the following code:
1 // Fig. 29.21: Validate.java
2 // validate user information using regular expressions.
3 import java.util.Scanner:
4
5 public class Validate
6
7 public static void main(String[] args)
B {
9
1/ get user input
10
Scanner scanner = new Scanner(System.in);
11
System.out.println(“Please enter first name:” );
12
String first Name = scanner.nextLine();
13
System.out.println(“Please enter last name:” );
14
String lastName = scanner.nextLine();
15
System.out.println(“Please enter address:” );
16
String address = scanner.nextLine();
17
System.out.println(“Please enter city:” );
18
String city = scanner.nextLine();
19
System.out.println(“Please enter state:” );
20
String state scanner.nextLine();
21
System.out.println(“Please enter sip:” );
22
String sip = scanner.nextLine();
23
System.out.println(“Please enter phone:” );
String phone = scanner.nextLine():
25 } // end main
26 } // end class Validate
1. Write a validation class “Validatelnput” that check: firstName, last Name, address, city,
zip, and phone.
2. Apply the validation methods and execute the code.
17
Output – Java Applications (run) X
AAS
Please enter First name:
anal
Please enter last name:
almana
Please enter address:
123 stret
Please enter city:
riyadh
Dlease enter state:
centeral
Please enter zip:
12345
Dlease enter Phone:
234-345-6789
Output – JaveApplications (run)
run:
>
Please enter first name:
Anal
Please enter last name:
are almana
Please enter address:
123 streeX
Please enter city:
Riyadh
Please enter state:
centeral
Please enter ip:
234
Please enter Phone:
234-678-4523
Validate Result:
Invalid first name
BUILD SUCCESSFUL (total time: 29 seconds
Validate Result:
Invalid sip code
BUD SUCCESSUS (total time: 36 seconds
Sample OUTPUT
Output – Java Applications (run) X
DD zun
Dlease enter first name:
Amel
Please enter last name:
OR almana
பம்
Dlease enter address:
123 streetx
Please enter city.
Riyadh
Please enter atate:
centeral
Please enter zip:
12345
Dlease enter phone:
3324669976
Output – JavaApplications (run) |
DD run:
DD Please enter first name:
Amal
Please enter last see
Almana
Please enter address:
123 street
Please enter city:
Riyadh
Please enter state:
Canteral
Please enter aip:
12345
Please enter phone:
234-235-3443
Validate Result:
Valid Input. Thank you.
BUILD SUCCESSFUL (total time: 38 seconds)
Validate Result:
Invalid phone number
BUILD SUCCESSFUL (total time: 34 seconds)
18