-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidator.java
More file actions
56 lines (51 loc) · 1.69 KB
/
Copy pathValidator.java
File metadata and controls
56 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
public class Validator {
public static Scanner input = new Scanner(System.in);
public static String ValidateProductID(){
System.out.println("Validating Product ID...");
String ID;
System.out.print("Enter the product ID : ");
while(true) {
ID = input.next();
if (ID.startsWith("E")) {
System.out.println("The product ID entered is valid.");
break;
} else if (ID.startsWith("C")) {
System.out.println(" The product ID entered is valid.");
break;
} else {
System.out.println(" The product ID entered is invalid.");
System.out.print("Please enter a valid product ID : ");
}
}
return ID;
}
public static int StringtoInteger(){
int num = 0;
while(true) {
if (input.hasNextInt()) {
num = input.nextInt();
break;
} else {
System.out.println("Invalid Input. Please enter an integer.");
System.out.print("Please enter the correct input : ");
input.next();
}
}
return num;
}
public static double StringtoDouble(){
double num = 0;
while(true) {
if (input.hasNextDouble()) {
num = input.nextDouble();
break;
} else {
System.out.println("Invalid Input. Please enter a valid double or floating number as double.");
System.out.print("Please enter the correct input : ");
input.nextLine();
}
}
return num;
}
}